tags:

views:

706

answers:

6

Is there a way to select data where any one of multiple conditions occur on the same field? Example: I would typically write a statement such as:

select * from TABLE where field = 1 or field = 2 or field = 3

Is there a way to instead say something like:

select * from TABLE where field = 1 || 2 || 3

?

+11  A: 

Sure thing, the simplest way is this:

select foo from bar where baz in (1,2,3)
mercutio
+3  A: 
select * from TABLE where field IN (1,2,3)

You can also conveniently combine this with a subquery that only returns one field:

    select * from TABLE where field IN (SELECT boom FROM anotherTable)
Michael Stum
+2  A: 

select * from TABLE where field in (1, 2, 3)

Mike Polen
+2  A: 
WHERE field IN (1, 2, 3)
Lasse V. Karlsen
A: 

OR:

SELECT foo FROM bar WHERE baz BETWEEN 1 AND 3
Can Berk Güder
A: 

You can still use in for

select *
from table
where field  = '1' or field = '2' or field = '3'

its just

select * from table where field in ('1','2','3')
Re0sless