0

I am trying to search a table where the field name does not have a list of strings in it. I use:

SELECT * FROM members WHERE name NOT IN ('bob', 'jim', 'leroy'); 

but it still returns matches containing those words. I have searched high and low for the answer to this. Can anyone help?

1
  • 1
    could you please post a data set containing one of the names you want to filter out? Commented Oct 17, 2010 at 22:48

2 Answers 2

3

name NOT IN ('bob', 'jim', 'leroy') is equivalent to name!='bob' and name!='jim' and name!='leroy'.

Perhaps you want

name not like '%bob%' and name not like '%jim%' and name not like '%leroy%' 

instead?

Sign up to request clarification or add additional context in comments.

6 Comments

yeah but I thought there would be a more efficient way, perhaps not
@Adam within mysql I think that's as good as it gets. If you need to improve performance look into an external search engine like sphinxsearch.com .
@OMG Ponies - I suppose I should have mentioned that, but I didn't because it's way slower. Might be good enough for his needs though.
Slower than a table scan? I don't think so, but constraining because of only supporting MyISAM.
|
1

This only NOT matches values that are exactly one of the names. You can try WHERE name NOT LIKE "%bob%" AND NOT LIKE "%jim%" AND NOT LIKE "%leroy%"

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.