Steven Dale
Steven Dale

Reputation: 35

MYSQL Not equal to "IN" query

I have a table with loads of id's but I don't want to select around 10 id's

First I tried multiple OR but that didn't work then found the IN

SELECT * FROM table WHERE id IN (10, 88, 99)

But this selects those numbers I want all the other numbers so a not equal to needs to go in somewhere

Upvotes: 0

Views: 2475

Answers (3)

Anderson Carniel
Anderson Carniel

Reputation: 1771

Try this:

 SELECT * FROM table WHERE id NOT IN (10, 88, 99)

Hope this helps

Upvotes: 4

Tadeck
Tadeck

Reputation: 137290

Correct query is:

SELECT * FROM `table` WHERE `id` NOT IN (10, 88, 99)

And your attempt with "multiple ORs" failed probably because of it should involve "multiple ANDs" and negations like that:

SELECT * FROM `table` WHERE `id`!=10 AND `id`!=88 AND `id`!=99

Upvotes: 2

Sparky
Sparky

Reputation: 15085

Select * from table where Id NOT IN (10,88,99)

Upvotes: 3

Related Questions