我正在尝试获取其中存在子记录数量的类别列表。如果类别没有记录,它应该返回 NULL 或 0,但我的查询返回带有子记录的类别看起来就像它跳过了没有子记录的类别。...将非常感谢您的帮助。
这是我的代码:
SELECT
t_gal.f_sub_category_id,
t_sub_cat.f_sub_cat_name,
t_gal.f_image_thumb, (
SELECT COUNT(*)
FROM t_gallery
WHERE f_sub_category_id = t_gal.f_sub_category_id)
AS f_image_total
FROM t_gallery t_gal
LEFT JOIN t_sub_category t_sub_cat ON t_sub_cat.r_id = t_gal.f_sub_category_id
GROUP BY t_sub_cat.r_id
ORDER BY t_gal.f_added_on DESC, t_gal.r_id DESC
这是两张表: