• Im working on a widgets that provides me the newest comments in a given area. I want to make sure, that just the newest comment (and only one per post) are shown.

    Therefore i want to group the comments by comment_post_ID.

    But if i do
    “SELECT comment_ID, comment_post_ID FROM wp_comments GROUP BY comment_post_ID”

    i get the message:
    “SELECT list is not in GROUP BY clause and contains nonaggregated column ‘wp_comments.comment_ID’ which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by.

    Any idea how to solve this? Struggeling with this for a while now.

Viewing 3 replies - 1 through 3 (of 3 total)
  • I think the way GROUP BY works is that whatever you are grouping by should be in your SELECT clause – and that kind of makes sense doesn’t it ?

    So I think this should be the query you are looking for:

    “SELECT comment_post_ID, comment_post_ID FROM wp_comments GROUP BY comment_post_ID”

    I think this should fix it.

    Thread Starter sellfisch

    (@sellfisch)

    Yes thank you

    Oh gosh ! My bad, I already see you have added it there. Sorry. Is comment_ID from the same table?

    Can you just lay down the table structure? Just want to know if you have kept the table as is or modified it ?

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘MYSQL: Group comments by comment_post_ID’ is closed to new replies.