本文介绍了MYSQL COUNT返回NULL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用谷歌搜索了问题,但没有得到答案。
我想列出以下sql的所有结果,包括NULL(当COUNT(review.id)也返回0时),但是我只得到了仅包含评论的地方的结果。

I have googled my problem but didnt get the answer.I want to list all of the results of below sql including NULL (when COUNT(review.id) return 0 also) but instead i just got the results of articles of place that only contains review.

$sql = "SELECT tbl_place.id, tbl_place.region_id, tbl_place.subregion_id, tbl_place.title, tbl_place.metalink, tbl_place.img_thumbnail, tbl_place.summary, tbl_place.category1_id, tbl_place.category2_id, tbl_place.category3_id, COUNT(review.id) AS total_review FROM tbl_place
        JOIN review ON tbl_place.id = review.place_id
        WHERE
        tbl_place.category1_id = '32'   AND 
        tbl_place.status = '1'          AND
        review.rating != '0.00'         
        GROUP BY tbl_place.id
        ORDER BY total_review $by
        LIMIT $limit OFFSET $offset";


推荐答案

请对检查表使用左联接,而不是联接。默认情况下,join是内部联接,因此将只接受匹配的记录。

please use left join for review table instead of join. join is by default inner join so it will take only matched records.

这篇关于MYSQL COUNT返回NULL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 21:08