Another dumb question....
Code:
SELECT e.eventName
FROM events e
INNER JOIN eventCharities ec ON e.idEvents = ec.idEvents
INNER JOIN charities c ON ec.idCharities = c.idCharities
INNER JOIN userCharities uc ON uc.idCharities = c.idCharities
WHERE uc.idUsers = 42
That will get me all events that are associated with one of the user's favourite charities.
However, I also have a table "userEvents" (guess what that does) - I'd like to amend the query above so that it DOESN'T include the events that the user is already taking part in.
The only way I can think of is to plonk a subquery on the bottom. This seems a bit... clunky. Is there a better way?
Code:
SELECT e.eventName
FROM events e
INNER JOIN eventCharities ec ON e.idEvents = ec.idEvents
INNER JOIN charities c ON ec.idCharities = c.idCharities
INNER JOIN userCharities uc ON uc.idCharities = c.idCharities
WHERE uc.idUsers = 42
AND events.idEvents NOT IN (SELECT idEvents FROM userEvents WHERE idUsers = 42)
Thanks
