php - Mysql's left join query, when a field in the right table is empty, why can't the corresponding field in the left table be found?
高洛峰
高洛峰 2017-06-05 11:08:00
0
2
430
SELECT category.c_id,category.c_name,jobs.amount FROM qs_category as category 
LEFT JOIN qs_jobs as jobs ON category.c_id=jobs.trade 
WHERE jobs.addtime >= 1483200000 AND jobs.addtime <= 1498838400 

This is the query statement. The left table category is the classification table, and the right table jobs is the position table. I want to count the number of positions under each category.
But there is a problem with the result. If a certain category does not exist in the category field of the job table, that is to say, no one has added a position under this category, then this category will not be displayed in the query results.
But it stands to reason that if there is a left join, even if there is no corresponding data in the right table, the fields in the left table should still be displayed

高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

reply all(2)
刘奇

Of course, the table on the right where you wrote the where condition cannot be found. When the right table is empty, the condition field is also empty, and it is filtered out by your where condition.

漂亮男人

I have also encountered this situation. It was filtered out by your where condition. The solution is to append the conditions written in where to on!
where is to filter the result set after connecting the tables, but if the condition in on is false, the data in the left table will be returned, and the right table will be empty

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!