删除A表中未被B表使用的数据

查询address中未被thing过使用的地址

select * from address where not exists (select 1 from thing where thing.address_id = address.id);

删除只需要把select * 换为delete即可

删除address中未被thing过使用的地址

delete from address where not exists (select 1 from thing where thing.address_id = address.id);

你可能感兴趣的:(删除A表中未被B表使用的数据)