PDA

View Full Version : SQL Query to select users who have NOT voted


Luke Brown256
03-15-2007, 08:46 AM
Hi i am trying to write an SQL query that would select all users from a specific usergroup who have NOT voted in a specific poll:


SELECT vb3_user.*
FROM vb3_user LEFT JOIN vb3_pollvote ON vb3_user.userid=vb3_pollvote.userid
WHERE vb3_pollvote.userid IS NULL
AND vb3_pollvote.pollid = 240
AND vb3_user.usergroupid =26

that is what i have got so far, but it returns blank results, can anyone assist with this?

Luke Brown

Marco van Herwaarden
03-15-2007, 08:53 AM
WHERE vb3_pollvote.userid IS NULL
AND vb3_pollvote.pollid = 240

That will never be true. Either the userid is null (ie. no match) or the pollid has a value, never both at the same time.

Try:
SELECT vb3_user.*
FROM vb3_user LEFT JOIN vb3_pollvote ON (vb3_user.userid=vb3_pollvote.userid AND vb3_pollvote.pollid = 24)
WHERE vb3_pollvote.userid IS NULL
AND vb3_user.usergroupid =26