Example table:
ID, foreign_id, status
The ID is unique, the foreign_id is not. Example rows:
1, 1111, 0
2, 2222, 0
3, 3333, 1
4, 1111, 1
5, 4444, 0
What I want to select is unique foreign_id's that only have the status as 0. If it has a status as 0 but another row with the same foreign ID has a status as 1, don't select that foreign_id. Expected output:
1, 2222, 0
5, 4444, 0
I can select where status = 0 and group by foreign_id, but that will just select the row where status is 0 even though there may be another row with the same foreign_id and status as 1.
SELECT ID, foreign_id
FROM table
WHERE status = 0
GROUP BY foreign_id
Any help appreciated.


