美文网首页
删除A表中未被B表使用的数据

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

作者: 晓函 | 来源:发表于2022-08-08 14:51 被阅读0次

    查询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表使用的数据

          本文链接:https://www.haomeiwen.com/subject/ixmwwrtx.html