I have two tables (cars and car_images)
cars
----
id
brand
model
...
car_images
----------
id
car_id
name
...
Every car can have multiple images ...
What is the best way to select all cars with their images ?
That's how I do it with Native PHP PDO, but I don't know if it's the best and fastest way ...
$sth = $dbh->query("SELECT * FROM cars");
$sth_images = $dbh->prepare("SELECT * FROM car_images WHERE car_id = :car_id");
while($row = $sth->fetch()){
$sth_images->execute(['car_id' => $row['id']]);
// ...
}
LEFT JOINinstead