For example, I have a table with 2 columns (int)id and (varchar)name. And I have 10 id to get each one’s name.
Considering performance, Shall I query them one by one in a loop or query them with statement like WHERE ID= N OR ID= M... OR...?
For example, I have a table with 2 columns (int)id and (varchar)name. And I
Share
You should definitely batch the queries into one call. A general rule of thumb for efficiency is to minimize the number of queries you make to MySQL. One query for this is way faster than ten. But you don’t have to use
ORfor this, there is a special syntax for it:This means the same thing as
SELECT ... WHERE id=1 OR id=2 OR id=3 OR id=4 OR id=5