panthro
panthro

Reputation: 24099

Exclude 2 rows from select

I know I can exclude a row like so:

SELECT * FROM products WHERE id <>1

But I need to exclude 2 products, I've tried:

SELECT * FROM products WHERE id <>(1,2)

But no luck.

Upvotes: 0

Views: 47

Answers (2)

Manashvi Birla
Manashvi Birla

Reputation: 2843

Try this

SELECT * FROM products WHERE id  not in (1,2)

IN is definately faster than OR. See this MYSQL OR vs IN performance

Upvotes: 3

Praveen Kumar Purushothaman
Praveen Kumar Purushothaman

Reputation: 167250

Use NOT:

SELECT * FROM `products` WHERE `id` NOT IN (1, 2);

Performance wise, IN is faster than comparison!

Upvotes: 0

Related Questions