2

i am wondering if their is a better way of doing something like this:

SELECT * 
FROM tableA 
WHERE colour='red' OR colour='greed' OR colour='blue' OR colour='yellow' 

is their anything like this:

SELECT * 
FROM tableA 
WHERE colour='red''greed''yellow'

cheers in advance

Joe Stefanelli
  • 132,803
  • 19
  • 237
  • 235
Jono
  • 17,341
  • 48
  • 135
  • 217

3 Answers3

7

Try the SQL IN operator

SELECT * FROM tableA WHERE colour in ('red','greed','yellow');
James Wiseman
  • 29,946
  • 17
  • 95
  • 158
3

Note that the IN operator will not handle a NULL case the way some people might expect:

SELECT *
FROM tbl
WHERE color = 'blue' OR color IS NULL

is not the same as:

SELECT *
FROM tbl
WHERE color IN ('blue', NULL)

While this may seem obvious to look for in code, it can be pernicious when the IN is a sub-select, and NULLs are in the inner results:

SELECT *
FROM tbl
WHERE color IN (SELECT color FROM tbl2)

And it exhibits possibly even more unexpected behavior in the NOT IN case

Community
  • 1
  • 1
Cade Roux
  • 88,164
  • 40
  • 182
  • 265
2

The IN Operator should be able to do what you need it to.

see http://www.w3schools.com/sql/sql_in.asp

Basically you could say

SELECT * FROM tableA WHERE colour IN ('red','green','yellow')

Dan Cramer
  • 685
  • 1
  • 9
  • 14