I'm trying to select all members who have not registered for an event. I have tables 'members', 'events', and 'events_members', the latter a join table with event_id and member_id columns.

The closest I've gotten is with this query:

SELECT m.id, m.first_name, m.last_name
FROM members AS m
RIGHT JOIN events_members AS em ON
        (em.event_id = 10 AND m.id != em.member_id)
ORDER BY m.last_name ASC;

This returns an empty set IF there are no records at all in events_members with event_id = 10. But, in that case, I want to receive ALL members.

However, if I add a single record with event_id = 10, I then get the expected list of all OTHER members. How can I modify this query so that, when there are 0 registered members for a particular event, I get back all members?

Obviously, I could always first check for the existence of the event_id in the join table and, if not found, run the select on the members table. But I doubt that that's the best option.

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/mysql?unsub=arch...@jab.org

Reply via email to