It is obvious that executing database query in loops has performance issues. but if the query is used as prepared statement, does it make any difference?
What is preferable joining together the tables and get the results or using prepared statement in loop?
Using
joinwould almost always be preferred instead of looping over a result set to get additional results.Relational Database Management Systems are built for combining related results, and does so very efficiently… additionally, this will you save many round trips to the database, which can become costly if used excessively – regardless of if you’re using prepared statements or not.