I have read this question as it seemed similar but it does not quite work for my scenario and I have not been able to adapt this solution to my problem: Left Join With Where Clause
My SQL query currently includes a join on the JOBS
table on the column production_id
like this:
SELECT md.production_id,manufacture_id, pr.product_code,j.production_id as jobs,j.job_type
FROM MANUFACTURE_DATE md
INNER JOIN PRODUCTS pr
on md.production_id = pr.production_id
LEFT JOIN JOBS j
on md.production_id = j.production_id
WHERE active='1' AND date='2021-09-09'
ORDER BY product_code DESC;
This returns a product_code
which has a record in the jobs
table with a job_type
of 3
On the join with the JOBS
table I now only want to include values with an job_type=1
but not job_type=2 or job_type=3
so I have included a WHERE clause in the join as below:
SELECT md.production_id,manufacture_id, pr.product_code,j.production_id as jobs,j.job_type
FROM MANUFACTURE_DATE md
INNER JOIN PRODUCTS pr
on md.production_id = pr.production_id
LEFT JOIN JOBS j
on md.production_id = j.production_id AND j.job_type=1
WHERE active='1' AND date='2021-09-09'
ORDER BY product_code DESC;
This returns the product_code which has a record in the jobs
table and displays NULL for jobs.production_id and jobs.job_type
My aim is to not have this product_code displayed at all because it is present in the JOBS table but not with the desired job_type
of 1.