I want to run a query to get user photo album ids, names, and picture count in the album. This query works:
SELECT album.id, album.name, count(pictures.*)
FROM album
LEFT JOIN pictures
ON (pictures.album_id=album.id)
WHERE album.owner = ?
GROUP BY album.id;
I have tons of pictures, and lots of albums, but the join is running before filtering for the user I'm interested in.
I have seen other answers that filter inside the join based on the 2nd table's values, but I want to filter on album.owner which is not included in the 2nd table. How can I filter before the join? (and is it efficient? will I break indexes?)