I'm trying to query a many to many relationship to see if one tag exists but not another. I'm trying to do this within one simple query.
I've asked a few friends and have checked stack overflow and can't seem to find someone who's trying to do something similar. I setup a SQLFiddle page which shows what I'm trying to do.
http://sqlfiddle.com/#!9/22b741b/8
In the example I have three users: Mike, Alice and George.
I have 7 candy bars: Snickers, Hersheys, Milky Way, KitKat, Reeses, Twizzlers and Sour Patch.
Mike likes Snickers, KitKat, Reeses and Twizzlers.
Alice likes KitKat, Hersheys and Sour Patch.
George likes KitKat and Twizzlers.
I want to find out who likes Twizzlers but not Snickers.
This is the code I have so far. With this I get back Mike and George. I only want George. How can I modify the query to give me the results I'm looking for?
SELECT Users.firstname, Candy.candyname
FROM Users
INNER JOIN UsersCandy ON Users.id = UsersCandy.user_id
INNER JOIN Candy ON UsersCandy.candy_id = Candy.id
WHERE Candy.candyname = 'Twizzlers'
AND Candy.candyname != 'Snickers'