單表刪除
說到刪除數(shù)據(jù),我們平時用到的大多是單表刪除:
delete from _table where id = 1;
關(guān)聯(lián)刪除
如果現(xiàn)在有兩個表 table1 和 table2,我們要刪除 table1 的數(shù)據(jù),并且只刪除 id 跟 table2 相同的數(shù)據(jù),則可以這樣寫:
delete from table1 inner join table2 on table1.id = table2.id;
如果還想繼續(xù)篩選刪除的條件,還可以加上 where 語句:
delete from table1 inner join table2 on table1.id = table2.id where table2.status = 2;
以上就是關(guān)聯(lián)刪除的教程,希望對您有所幫助!
簡書作者 小菜荔枝原創(chuàng) 轉(zhuǎn)載請聯(lián)系作者獲得授權(quán)