update/delete where in select 當in的數量過大給性能帶來很大問題
聯表更新
![](https://img.laitimes.com/img/__Qf2AjLwojIjJCLyojI0JCLicmbw5ichR3cf52bjl2LcNXZnFWbp9CXt92YuUWelRXauYjM5cmbvlXZkVHavw1LcpDc0RHaiojIsJye.png)
update items,month set items.price='12' where items.id=month.id;
update a left join b on a.id=b.a_id set a.title='aaaaa',b.body='bbbb' where a.id=1
注意:多表 update 不可以使用 order by 或 limit。
聯表删除
從資料表t1中把那些id值在資料表t2裡有比對的記錄全删除掉
![](https://img.laitimes.com/img/__Qf2AjLwojIjJCLyojI0JCLicmbw5ichR3cf52bjl2LcNXZnFWbp9CXt92YuUWelRXauYjM5cmbvlXZkVHavw1LcpDc0RHaiojIsJye.png)
delete t1 from t1,t2 where t1.id=t2.id
//delete from t1 using t1,t2 where t1.id=t2.id
從資料表t1裡在資料表t2裡沒有比對的記錄查找出來并删除掉
![](https://img.laitimes.com/img/__Qf2AjLwojIjJCLyojI0JCLicmbw5ichR3cf52bjl2LcNXZnFWbp9CXt92YuUWelRXauYjM5cmbvlXZkVHavw1LcpDc0RHaiojIsJye.png)
delete t1 from t1 left join 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
從兩個表中找出相同記錄的資料并把兩個表中的資料都删除掉
![](https://img.laitimes.com/img/__Qf2AjLwojIjJCLyojI0JCLicmbw5ichR3cf52bjl2LcNXZnFWbp9CXt92YuUWelRXauYjM5cmbvlXZkVHavw1LcpDc0RHaiojIsJye.png)
delete t1,t2 from t1 left join t2 on t1.id=t2.id where t1.id=25
注意此處的delete t1,t2 from 中的t1,t2不能是别名