0

I've got an issue, I am trying to collect a number of defined emails from a database, I collect them via the ID of each client.

Therefore, I currently have 1000 users in the database and I only want the emails from IDs 10, 11, 23, 34, 56, 33, 340, 433, 434, etc...

Besides the "

SELECT email FROM users WHERE id=10 OR id=11 OR id=23 OR id=34... 

etc" is there any other method that I could includes all the IDs simultaneously without having to write an OR condition each time and ID is added?

Thank you.

Alexis Pigeon
  • 7,423
  • 11
  • 39
  • 44
Crys Ex
  • 335
  • 1
  • 4
  • 9

3 Answers3

2

Use the IN operator:

WHERE id in (10, 11, 23, 34, ....)
Marc B
  • 356,200
  • 43
  • 426
  • 500
2

Use IN

SELECT email 
FROM users 
WHERE ID IN (34, 56, 33, 340, 433, 434)
John Woo
  • 258,903
  • 69
  • 498
  • 492
1
SELECT email FROM users WHERE id IN (10, 11, 23, 34, 56, 33, 340, 433, 434);
hjpotter92
  • 78,589
  • 36
  • 144
  • 183