Select where IN vs individual selects

Hello,

I need to select multi-rows (by ids) from a table with 500k+ rows and I have to make a query to get 10 rows at once (at maximum 20).

What is the difference in speed if I do 1 WHERE IN() query vs multi WHERE id = ‘’ in this case?

Is there a lot of difference // which way is preferable?

My code is much cleaner with the single queries option…

Thanks for help

one query with WHERE ID IN ( n1, n2, n3, … )

performance will be the same as one query with WHERE id = n1 OR id = n2 OR id = n3 …

but the guy who gets to maintain your query will thank you for using IN

:wink:

What about WHERE IN() vs separate queries - new, single sql query for each id instance ?

Thank you!

best: one query with WHERE id IN ( values )

good: one query with WHERE id = value OR id = value OR id = value

poor: separate queries with WHERE id = value

Is there any way to give WHERE id IN() instruction to sort the retrieved queries by the id order in ID(id1, id2, id3, …) ?

Thanks for help

yes, use the FIELD function

ORDER BY FIELD(id,id1,id2,…)