Using IN clause vs. multiple SELECTs
mysql, php
Solution
I'm pretty sure the second option gives you the best performance; one query, one result. You have to start looking for > 100 items before it may become an issue.
See also the accepted answer from here: MySQL "IN" operator performance on (large?) number of values
Problem
I was wondering which of these would be faster (performance-wise) to query (on MySQL 5.x CentOS 5.x if this matters): ``` SELECT * FROM table_name WHERE id=1; SELECT * FROM table_name WHERE id=2; . . . SELECT * FROM table_name WHERE id=50; ``` or... ``` SELECT * FROM table_name WHERE id IN (1,2,...,50); ``` I have around 50 `id`s to query for. I know usually DB connections are expensive, but I've seen the `IN` clause isn't so fast either [sometimes].