mysql join update

有時候刪除資料必須關聯另一張表才能篩選出來
就必須update和join 同時
update table1 ,table2
set table1.column = table2.column
where table1.column2 = table2.column2
或者
update table1 inner join table2 on (table1.column2 = table2.column2)
set  table1.column = table2.column
where table1.column2 = table2.column2
 
那delete呢?
其實也是一樣
 
delete
from table1   
    using  table1    join table2  on table1.column2 = table2.column2
where  ….
 
本篇發表於 有時候也很讓人頭痛的SQL。將永久鏈結加入書籤。

發表留言