0

I have read several posts about similar issues but all of them were problems in the code while mine even occurs in the mysql sequel console.

my query: SELECT * FROM users WHERE id IN ("1,2") ORDER BY id DESC

My Users table currently contains two users - one with id 1 and the other one with id 2 so actually both should be returned. Unfortunately only the first row gets returned

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
noa-dev
  • 3,561
  • 9
  • 34
  • 72

1 Answers1

3

The IN operator does not parse strings, leave out the double quotes:

SELECT * FROM users WHERE id IN (1,2) ORDER BY id DESC
Niels Keurentjes
  • 41,402
  • 9
  • 98
  • 136
  • 2
    And just to add a little more explanation: the reason it **is** matching user ID=1 is because MySQL parses the string "1,2" into the number "1" (ie. it ignores the comma and everything after it). – Kryten Dec 08 '15 at 14:20