user1396982
user1396982

Reputation: 125

mysql exclude names from blocked table

I am trying to block certain lists, this is a command I have tried

SELECT * FROM USER LIMIT 0, 50 WHEREnameNOT IN (SELECT * FROMexclude)

my exclude table contain user name i want block it but appears to be not working.

Upvotes: 0

Views: 129

Answers (2)

Kickstart
Kickstart

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

Legion
Legion

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

Related Questions