Reputation: 681
I am quite new about queries and I would like to know if there is an easier solution for the query I am working on.
For instance I want to get the data where x is 5,7,9,11,13,15 and 17.
I have a query like below;
SELECT * FROM abc WHERE x = 5 or x = 7 or x = 9 or x = 11 or x = 13 or x = 15 or x = 17;
Is it okay to use this query or are there any other simpler and efficient solution?
EDIT
Does it affect the perfomance when I use x=[5,7,8,11,13,15,17] vs x=[5,11,7,15,8,17,13]
X is the ID of another category for instance.
Upvotes: 1
Views: 199
Reputation: 204746
This is shorter but performs equally
SELECT * FROM abc WHERE x in (5,7,9,11,13,15,17)
But remember if one entry in the in
clause is null
then it returns FALSE.
Upvotes: 3