I\'m having an inner debate at my company about looping queries in this matter:
$sql = \"
SELECT foreign_key
FROM t1\";
foreach(fetchAll($sql) as $row)
The join
method is generally considered better, if only because it reduces the overhead of sending queries back and forth to the database.
If you have appropriate indexes on the tables, then the underlying performance of the two methods will be similar. That is, both methods will use appropriate indexes to fetch the results.
From a database perspective, the join
method is far superior. It consolidates the data logic in one place, making the code more transparent. It also allows the database to make optimizations that might not be apparent in application code.