我现在有一个表:tab1中有二个字段会别是id,contentId二个共同为主键
另一个表tab2中二个字段分别是:contentid,child_contentId,分别是tab1中对应contentId的外键
四个都有index
现在我通过一个tab1中的id把tab2中的所有相关数据都删除掉,这个sql怎么写?
开始写了个:
delete from tab2 where contentid in (select contentid from tab1 where id = ?)
or child_contentId in (select contentid from tab1 where id = ?)
不过写完就发现这样太烂了在线求一个最优的删除sql。谢谢了。
另一个表tab2中二个字段分别是:contentid,child_contentId,分别是tab1中对应contentId的外键
四个都有index
现在我通过一个tab1中的id把tab2中的所有相关数据都删除掉,这个sql怎么写?
开始写了个:
delete from tab2 where contentid in (select contentid from tab1 where id = ?)
or child_contentId in (select contentid from tab1 where id = ?)
不过写完就发现这样太烂了在线求一个最优的删除sql。谢谢了。
where exists(select * from tab1 where tab2.contentid=tab1.contentid or tab1.contentid=tab2.child_contentid)
where exists(select id from tab1 where tab2.contentid=tab1.contentid or tab1.contentid=tab2.child_contentid)