James
James

Reputation: 33

MYSQL - Is there a better way to query multiple unique values than using a large statement containing "OR"s

I have a simple MySQL query that looks something like this

SELECT *
FROM table
WHERE (id = 1173)
OR (id = 223)
OR (id = 363443)
OR (id = 11532)
OR (id = 45663)
OR (id = 28313)
OR (id = 717713)
OR (id = 128313)

And so on with about 10-100 ORs per query.

I'm just wondering if there's a more efficient or cleaner way of performing this query.

Upvotes: 3

Views: 95

Answers (1)

ace
ace

Reputation: 7583

Yes. You can use IN, like this

SELECT * FROM table WHERE id IN (1173,223,363443,11532,45663,28313,717713,128313)

Upvotes: 6

Related Questions