For example, I have a table Person having an ID for each entry and I have a table PersonEvent which records the personID of each person at an event.
If PersonEvent contains no rows for the event, everyone in the Person table attended. However if there are entries in the PersonEvent table, only those people attended the event.
I want to do a query such as:
SELECT *
FROM Person p
WHERE ((SELECT COUNT(*)
FROM PersonEvent pe
WHERE pe.personID = p.ID
AND pe.eventID = '290') = 0
OR EXISTS
(SELECT *
FROM PersonEvent pe
WHERE pe.personID = p.ID
AND pe.eventID = '290'))
How do I do this?
1 Answer