我不确定问题,但看看:
我有3张桌子:
现在我正在尝试获取此信息(查询):
$String = "SELECT
categories.id AS catid,
categories.icon AS caticon,
categories.name AS catname,
subcategories.id AS scatid,
subcategories.name AS scatname,
subcategories.description AS scatdescription,
subcategories.category_id AS scatcatid,
COUNT(topics.id) AS tid,
topics.title AS ttitle,
topics.author AS tauthor,
topics.created AS tcreated
FROM
categories
LEFT JOIN
subcategories
ON
subcategories.category_id = 1
LEFT JOIN
topics
ON
subcategories.id = topics.subcategory_id
GROUP BY
categories.id";
结果:
5分类显示5 - 好的, 4个子类别在第一类中仅显示1个。
也许查询太长了?谢谢你的回答。
答案 0 :(得分:2)
此
LEFT JOIN
subcategories
ON
subcategories.category_id = 1
应该是这个
LEFT JOIN
subcategories
ON
subcategories.category_id = categories.id