I am trying to select all users from the user database which are NOT subscribed to a particular mail list. The inner query finds the user if it is a member of the list and the outer query selects all users where the inner result is zero rows.
SELECT u.userid, u.username, u.mail, u.name,
u.lastname, u.starting_year, u.userid AS UIDD
FROM userdb.users AS u
WHERE (SELECT COUNT(*) FROM maildb.lists AS l,
maildb.list_subscriptions AS s, userdb.users AS u
WHERE u.userid = UIDD
AND l.listid = '$LIST_ID_TO_LOOKUP'
AND s.userid = u.userid
AND s.listid = l.listid) = 0
ORDER BY u.starting_year DESC, u.lastname, u.name;
This worked just fine until I moved to a new server and updated many components, including MySQL.
Now I get an error when running this query:
#1054 – Unknown column ‘UIDD’ in ‘where clause’
Could this be a problem with an old syntax that is now depricated? I am now running MySQL 5.5.24.
Something like this, SELECT .. WHERE userid NOT IN (subquery)