1、從資料表t1中把那些id值在資料表t2裡有匹配的記錄全刪除掉1
delete t1 from t1,t2 where t1.id=t2.iddelete
from t1 using t1,t2 where t1.id=t2.id
2、從資料表t1裡在資料表t2裡沒有匹配的記錄查詢出來並刪除掉1
delete t1 from t1 leftjoin t2 on t1.id=t2.id where t2.id is
null
delete
from t1,using t1 left
join t2 on t1.id=t2.id where t2.id is
null
3.從兩個表中找出相同記錄的資料並把兩個表中的資料都刪除掉1
delete t1,t2 from t1 leftjoin t2 on t1.id=t2.id where t1.id=
25
注意此處的delete t1,t2 from 中的t1,t2不能是別名
delete t1,t2 from table_name as t1 leftjoin table2_name as t2 on t1.id=t2.id where table_name.id=
25(mysql 版本不小於5.0在5.0中是可以的)
delete table_name,table2_name from table_name as t1 left
join table2_name as t2 on t1.id=t2.id where table_name.id=
25
mysql 關聯刪除 mysql 關聯刪除
參考 原網頁廣告太多,自己抄了下。1 delete from t1 where 條件 2 delete t1 from t1 where 條件 3 delete t1 from t1,t2 where 條件 4 delete t1,t2 from t1,t2 where 條件 前3者是可行的,第4者...
mysql 的多表關聯刪除
在專案中經常會碰到多層表結構的設計,當碰到刪除的時候如果單個表逐一刪除,不僅犧牲效率還容易出錯。所以在mysql 4.0 推出了 跨表 delete 功能,簡單的說就是 可以在一個sql裡面對多張表的指定一條資料或多條資料進行刪除。現有 table1 和 table2 兩張表,他們的外來鍵是id,不...
mysql 級聯刪除
url create table roottb id int 11 unsigned auto increment not null,data varchar 100 not null default primary key id type innodb 最後一句話 type innodb 加上之後...