I want to be able to find rows in Category table with condition of visible = 0 not in the query result from below:
SELECT c.id as cat_id, j.id
FROM category c
LEFT JOIN portfolio_job_category pjc
ON pjc.category_id = c.id
LEFT JOIN job j
ON j.id = pjc.job_id
WHERE c.visible = 0
AND j.end_date > CURRENT_DATE
GROUP BY c.id
Is there a way to use NOT IN to find this?
I tried below but this loops forever and crashes mysqld
SELECT c.id
FROM category c
WHERE c.id NOT IN
(SELECT c.id as cat_id, j.id
FROM category c
LEFT JOIN portfolio_job_category pjc
ON pjc.category_id = c.id
LEFT JOIN job j
ON j.id = pjc.job_id
WHERE c.visible = 0
AND j.end_date > CURRENT_DATE
GROUP BY c.id)
AND visible = 0
What don’t you try using
LEFT JOIN