l2u
1
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
r937
2
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

l2u
3
What about WHERE IN() vs separate queries - new, single sql query for each id instance ?
Thank you!
r937
4
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
l2u
5
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
r937
6
yes, use the FIELD function
ORDER BY FIELD(id,id1,id2,…)