Reputation: 125
I am trying to block certain lists, this is a command I have tried
SELECT * FROM USER LIMIT 0, 50 WHERE
nameNOT IN (SELECT * FROM
exclude)
my exclude table contain user name i want block it but appears to be not working.
Upvotes: 0
Views: 129
Reputation: 21513
Recode it as a left join:-
SELECT `USER`.*
FROM `USER`
LEFT OUTER JOIN exclude
ON `USER`.name = exclude.name
WHERE exclude.name IS NULL
LIMIT 0, 50
However if you wanted to do it using the same style as before you would need to return the matching field from the select from exclude, not every field (ie, not SELECT *)
SELECT *
FROM `USER`
WHERE name NOT IN (SELECT name FROM exclude)
LIMIT 0, 50
Upvotes: 1
Reputation: 836
Try this :
SELECT * FROM USER LIMIT 0, 50 WHERE name NOT IN (SELECT name FROM exclude)
The most likely reason for your query not working is that the exclude
table probably has more than one column in it which would result in an error when you tried to run the query
Upvotes: 0