0

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.

panthro
  • 21,049
  • 61
  • 166
  • 295

2 Answers2

3

Try this

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

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

Community
  • 1
  • 1
Manashvi Birla
  • 2,839
  • 3
  • 13
  • 28
0

Use NOT:

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

Performance wise, IN is faster than comparison!

Praveen Kumar Purushothaman
  • 160,666
  • 24
  • 190
  • 242