table comment report
CREATE TABLE $comment_report_table (
`comment_id` int(11) unsigned DEFAULT NULL,
`user_id` int(11) unsigned DEFAULT NULL,
`reason` varchar(100) DEFAULT NULL,
INDEX `comment_id` (`comment_id`)
comment_id user_id reason
11 22 foo
11 3 aks
2 7 tettre
table comments
CREATE TABLE $comments_table (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`media_id` int(11) unsigned DEFAULT NULL,
`user_id` int(11) unsigned DEFAULT NULL,
`c_date` datetime,
`comment` longtext DEFAULT NULL,
PRIMARY KEY (`id`),
INDEX `media_id` (`media_id`)
id (primary) user_id comment c_date
02 3 ddwww 2023-01
09 5 www 2023-02
10 22 ee 2024-11
11 3 rrrrr 2024-02
12 7 gg 2025-01
query:
"SELECT crt.comment_id, crt.user_id as report_user_id, crt.reason as report_reason, ct.id, ct.comment, ct.user_id, ct.c_date
FROM $comment_report_table as crt
LEFT JOIN $comments_table ct on crt.comment_id = ct.id
GROUP BY crt.comment_id
ORDER BY ct.c_date DESC
this will return only 2 results from report table:
comment_id user_id reason
11 3 aks
2 7 tettre
I want all results from report table. It seems this skips results from report table with same comment_id
GROUP BY.crt-comment_id, there will be only one row ofcomment_id, so in this case, whichuser_idandreasonwill be selected?GROUP BYdoes. It groups data by whatever column(s) you put it there. In this case, there will be a row for eachcomment_id. That's why your query should not even have executed.dev.mysql.com/doc/refman/8.4/en/group-by-modifiers.html