Forum Moderators: open
I am trying to get results from my database where the item might be in the query many times. What is the most efficient query to achieve this?
SELECT *
FROM table
WHERE item = '1'
AND item = '2'
AND item = '25'
AND item = '105'
AND item = '990'
Is there a more efficient query that I should be using?
TIA,
-george
You will get no rows back from this query because a particular column in a row can only have one value.
You probably meant to use OR.
SELECT *
FROM table
WHERE item = '1'
OR item = '2'
OR item = '25'
OR item = '105'
OR item = '990'
If so, you could rewrite the query as:
SELECT *
FROM table
WHERE item IN ('1', '2', '25', '105', '990')
It doesn't run any faster but is easier to follow and maintain.