单表删除
说到删除数据,我们平时用到的大多是单表删除:
delete from _table where id = 1;
关联删除
如果现在有两个表 table1
和 table2
,我们要删除 table1
的数据,并且只删除 id
跟 table2
相同的数据,则可以这样写:
delete from table1 inner join table2 on table1.id = table2.id;
如果还想继续筛选删除的条件,还可以加上 where
语句:
delete from table1 inner join table2 on table1.id = table2.id where table2.status = 2;
以上就是关联删除的教程,希望对您有所帮助!
简书作者 小菜荔枝原创 转载请联系作者获得授权
网友评论