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
如何在不使用 PHP 的情况下合并两个查询?(限制 8 很重要!)