I have a query with NOT IN. I’ve heard MySQL doesn’t support NOT IN, but I can’t figure how to rewrite it.
My query is:
SELECT * FROM quests
WHERE id NOT IN ('" .$quest_completed. "')
AND location=" .$location_id. "
AND (follows=0 OR follows IN ('" .$quest_completed. "'))
ORDER BY title
eg:
SELECT * FROM quests
WHERE id NOT IN (6,21) AND
location=8 AND
(follows=0 OR follows IN (6,21))
ORDER BY title
Row id 6 is being returned in that when I specified WHERE id NOT IN 6
It looks like, because of your use of apostrophes around the
$quest_completedvariable, the query that’s actually being executed is likely to beNOT IN ('6,21'), rather thanNOT IN (6,21)(which I think is what you want?).The difference is that the first version returns records where
idis not equal to the string'6,21', whereas the second version returns records whereidis neither the number6nor the number21.