SQL
SELECT IFNULL(parent, id) as p
FROM article_comments
WHERE article_id = 3
GROUP BY p LIMIT 8
PHP
foreach ($result AS $data)
{
$parents .= $data['p'] . ',';
}
SQL
SELECT
*,
IFNULL(parent, id) AS p,
IFNULL(reply_comment_id, id) AS r
FROM article_comments
WHERE IFNULL(parent, id) IN('.$parents.') AND article_id = 3
ORDER BY p ASC, r ASC, date DESC
How to unite the two queries, without using PHP? (LIMIT 8 is important!)
1. With subquery
2. With temporary table
p.s. do not use mysql reserved words for you table fields (like date)