Crys Ex
Crys Ex

Reputation: 335

MySQL 'WHERE AND' issue

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.

Upvotes: 0

Views: 63

Answers (3)

hjpotter92
hjpotter92

Reputation: 80639

SELECT email FROM users WHERE id IN (10, 11, 23, 34, 56, 33, 340, 433, 434);

Upvotes: 1

John Woo
John Woo

Reputation: 263723

Use IN

SELECT email 
FROM users 
WHERE ID IN (34, 56, 33, 340, 433, 434)

Upvotes: 2

Marc B
Marc B

Reputation: 360702

Use the IN operator:

WHERE id in (10, 11, 23, 34, ....)

Upvotes: 2

Related Questions