Looking for a query to return orphan rows in a secondary table
On my website I share photos for my friends and family to see, and I use a MySQL database as the backend. Here is the design of the two databases in question:
tbl_albums:
album_id - The id of this photo album
parent_id - The id of the album containing this album (an album is basically like a directory in my model)
all_other_data - Several columns that don't relate to my question
tbl_images:
image_id - The id of the image
album_id - The id of the album to which this image belongs
all_other_data - Several columns that don't relate to my question
I'd like to run some queries occasionally to verify the integrity of my data. Specifically, I want to check for orphan images and albums--that is to say, those whose parent_ids are not actually in tbl_albums.
So I know what the queries would kind of look like, but I'm a bit confused on the WHERE clause:
1) select image_id from tbl_images, tbl_albums where (?? tbl_images.album_id is not in tbl_albums.album_id ??)
2) select album_id from tbl_albums where (?? parent_id is not in album_id ??)
I think I could do this with an embedded query, something like "where album_id is not in (select album_id from tbl_albums), but it seems like there might be another way to do this that is probably more efficient. I've read about LEFT JOIN queries that sound like they might do what I want, but I can't get the syntax right, and that doesn't help on the query that only involves one table.
Any suggestions?

