Looking for a query to return orphan rows in a secondary table

I apologize if this is a dumb question. I've been programming professionally for a few years but I have very little experience with database queries beyond the basic select/insert/update types that every programmer needs to know.

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?
[1833 byte] By [iempleh] at [2007-11-19 20:47:13]
# 1 Re: Looking for a query to return orphan rows in a secondary table
With Oracle and Access (and I presume it would work also with MYSQL), you could use NOT IN or NOT EXIST followed by a subquery:
select image_id
from tbl_images, tbl_albums
where tbl_images.album_id
not in (select tbl_albums.album_id from tbl_albums)
olivthill at 2007-11-9 13:43:28 >