我有两个表:network_mode: host
和news
。
我需要为新闻内容和评论数写一个查询。
我尝试过
comments
我想应该有很多“ AS”。有人可以帮助我吗?谢谢
答案 0 :(得分:0)
您缺少GROUP BY
:
SELECT n.id, n.title, n.date, n.author_name, n.short_content,
COUNT(c.comment) as cnt
FROM php_base.news n LEFT JOIN
php_base.comments c
ON n.id = c.news_id
GROUP BY n.id, n.title, n.date, n.author_name, n.short_content,
ORDER BY n.date DESC LIMIT 10