SELECT distinct crftd.path as storage_area_key FROM cr_files_to_delete crftd WHERE not exists (SELECT 1 FROM cr_revisions r WHERE r.content = crftd.path) delete from cr_files_to_delete