mysql 資料庫 多表關聯刪除

2021-06-29 07:42:54 字數 373 閱讀 9267

1、從資料表t1中把那些id值在資料表t2裡有匹配的記錄全刪除掉

delete t1 from t1,t2 where t1.id=t2.id    或delete from t1 using t1,t2 where t1.id=t2.id

2、從兩個表中找出相同記錄的資料並把兩個表中的資料都刪除掉

delete t1,t2 from t1 left join t2 on t1.id=t2.id where t1.id=25

3、刪除三張表中,指定字段值相同的資料;

delet t1,t2,t3 from t1 left join t2 on t1.id=t2.id inner join t3on t3.id=t1.id where t1.id=***x

mysql 多表關聯刪除

兩張表關聯刪除 delete a,b from table1 a inner join table2 b on a.id b.aid where a.id 1 或者也可以 delete a,b from table1 a,table2 b where a.id b.aid and a.id 1 三張...

mysql 多表關聯刪除

sql檔案 set foreign key checks 0 table structure for stu tea drop table ifexists stu tea create table stu tea stu id int 11 not null,tea id int 11 not n...

資料庫多表關聯查詢

本文主要列舉兩張和三張表來講述多表連線查詢。新建兩張表 表1 student 截圖如下 表2 course 截圖如下 此時這樣建表只是為了演示連線sql語句,當然實際開發中我們不會這樣建表,實際開發中這兩個表會有自己不同的主鍵。外連線可分為 左連線 右連線 完全外連線。1 左連線 left join...