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
  • 22,779
  • 66
  • 183
  • 324

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,837
  • 3
  • 14
  • 28
0

Use NOT:

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

Performance wise, IN is faster than comparison!

Praveen Kumar Purushothaman
  • 164,888
  • 24
  • 203
  • 252