Select IDs that doesn't exist

I have two tables: data and images

So, some IDs from table data were deleted in the meantime but I didn’t delete these IDs from the table images.

So, now I want to get all IDs that don’t exist in table data and delete these IDs in the table images.

Any idea?

Thanks.


select id from images where id not in (select id from data)

if this returns the correct id’s then change the query from a select to a ‘delete from’

Thanks.