Reputation: 18118
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
Upvotes: 2
Views: 77
Reputation: 89671
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
Upvotes: 3
Reputation: 685
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')
Upvotes: 2
Reputation: 30498
Try the SQL IN operator
SELECT * FROM tableA WHERE colour in ('red','greed','yellow');
Upvotes: 7