I have two sql queries, one which retrieves all the Event records for a given topic id and another which is supposed to retrieve all Event records excluding given topic id, but doesn’t.
The first query retrieves the correct records
SELECT `events`.*
FROM `events` INNER JOIN events_topics ON events.id = events_topics.event_id
WHERE (events_topics.topic_id = 75)
The second query which is supposed to exclude events does not exclude any.
SELECT `events`.*
FROM `events` INNER JOIN events_topics ON events.id = events_topics.event_id
WHERE (events_topics.topic_id <> 75)
What this means is that you have other
topic_idvalues inevents_topicfor a given event. A.k.a., if you havetopic_id = 75andtopic_id = 33for, say,eventid = 45,this eventid will be returned because the query matches ontopic_id = 33You have asked:
Change the query to EXISTS/NOT EXISTS which is correct. This is: