Using Inner Join instead of Left Join (Assuming all production_ids present in Manufacture Table are also present in Jobs Table)
SELECT md.production_id,manufacture_id,
pr.product_code,jobs.production_id as jobs,jobs.job_type
FROM MANUFACTURE_DATE md
INNER JOIN PRODUCTS pr
ON md.production_id = pr.production_id
INNER JOIN JOBS jobs
ON md.production_id = obs.production_id AND jobs.job_type=1
WHERE active='1' AND date='2021-09-09' ORDER BY product_code DESC;
Using same filter condition on job_type but in where clause along with one more condition:
SELECT md.production_id,manufacture_id,
pr.product_code,jobs.production_id as jobs,jobs.job_type
FROM MANUFACTURE_DATE md
INNER JOIN PRODUCTS pr
on md.production_id = pr.production_id
LEFT JOIN JOBS jobs
on md.production_id = jobs.production_id
WHERE active='1' AND date='2021-09-09'
AND (jobs.job_type=1 OR jobs.production_id IS NULL)
ORDER BY product_code DESC;
发布评论
评论(1)
解决问题的解决方案可以通过两种方式:
使用内部联接而不是左联接(假设制造表中存在所有生产_ID,也存在于工作表中)
)
使用Job_type上的相同过滤条件,但在其中的条款以及另一种条件:
为什么可以通过以下链接中给出的示例代码示例来解释您的错误:
The solution for your problem can be in two ways:
Using Inner Join instead of Left Join (Assuming all production_ids present in Manufacture Table are also present in Jobs Table)
Using same filter condition on job_type but in where clause along with one more condition:
Why you are going wrong can be explained through sample code example given at below link:
https://dbfiddle.uk/?rdbms=mysql_8.0&fiddle=876eb66e340e27b05ae543238b5a88ff