select * from a where a.id in ('1','2','3')
select * from a where a.id='1' or a.id='2' or a.id='3'
Which one is advisable?
select * from a where a.id in ( 1,2,3 )
Please note that if your
id column is numeric, you should not enclose the values in quotes, which makes them strings. Only MySQL performs the implicit conversion back to numeric; all other major database systems will give you a syntax error. Of course, if your
id column is actually a character column, then you would want to compare it to strings... but then, why would the character values be numbers?
Related Q&A from Rudy Limeback
Read SQL expert Rudy Limeback's advice for counting combinations in a table with SQL's GROUP BY clausecontinue reading
Read an example of an SQL case expression from our SQL expert Rudy Limeback.continue reading
Read about the Mimer Validator, a tool used to verify your SQL code, in this tip from SQL expert Rudy Limeback.continue reading
Have a question for an expert?
Please add a title for your question
Get answers from a TechTarget expert on whatever's puzzling you.