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,223
  • 11
  • 38
  • 44
Crys Ex
  • 315
  • 1
  • 4
  • 9

3 Answers3

2

Use the IN operator:

WHERE id in (10, 11, 23, 34, ....)
Marc B
  • 348,685
  • 41
  • 398
  • 480
2

Use IN

SELECT email 
FROM users 
WHERE ID IN (34, 56, 33, 340, 433, 434)
John Woo
  • 249,283
  • 65
  • 481
  • 481
1
SELECT email FROM users WHERE id IN (10, 11, 23, 34, 56, 33, 340, 433, 434);
hjpotter92
  • 75,209
  • 33
  • 136
  • 171