Reputation: 2666
Let's say I have a query like this:
SELECT * FROM table_name WHERE venue = "1" OR venue = "10"
That's great, works fine. But let's say I have a list of 50 venue numbers. Is there an easy way to do this where I don't have to write out 50 different ORs?
Thanks!
Upvotes: 0
Views: 780
Reputation: 12204
Not sure if MySQL supports this...
Use the BETWEEN
operator:
SELECT *
FROM table
WHERE venue BETWEEN '1' and '50';
Although you may need to be more explicit when dealing with character string datatypes:
SELECT *
FROM table
WHERE venue BETWEEN '1' and '9'
OR venue BETWEEN '10' and 50';
Of course, BETWEEN
won't help if your list of numbers are non-contiguous.
Upvotes: 0
Reputation: 642
Try...
SELECT * FROM table_name WHERE venue in ('1', '10')
I know it works in Oracle. "in" operator is probably part of standard SQL? Dunno.
edit: changed double to single quotes.
Upvotes: 0
Reputation: 10333
SELECT * FROM table_name WHERE venue IN ('1','10')
Best answer would be
SELECT * FROM table_name WHERE venue IN @myVar
Where @myVar is a list set in the query,
Upvotes: 1
Reputation: 2630
Use the IN
keyword: ... WHERE venue IN (2, 3, 5, 7, 11, ...) ;
Upvotes: 0