I am trying write a query which would return all programs that have category a and category b. The table structure is as follows:
Program
id
1000
1001
1002
Program_Category
program_id | category_id
1000 | 1
1000 | 2
Category
id | name
1 | category a
2 | category b
As you can see program 1000 has category a and category b. The query i am trying to use to retrieve the program is
SELECT DISTINCT t1.id
FROM PROGRAM t1
LEFT OUTER JOIN (PROGRAM_CATEGORY t2
JOIN CATEGORY t0 ON (t0.id = t2.category_id)
) ON (t2.program_id = t1.id)
WHERE ((t0.name = 'category a')
AND (t0.name = 'category b'))
This is currently returning 0 rows.