I have two tables, photo_albums and images.
photo_albums
- photo_albums_id: int(11)
- cover_photo_id: int(11)
images
- images_id: int(11)
- img_name: varchar(255)
- photo_albums_id: int(11)
I need to query the database to return all the photo albums, only once, plus the img_name of the cover_photo_id associated with each album. I don't want to return all the photos in each album. It also needs to work if there is no cover image associated with the album. This returns all the photo albums:
SELECT * FROM photo_albums ORDER BY photo_albums_id;
But I'm not sure how to get the following bit to work:
SELECT * FROM images WHERE image_id = cover_photo_id;