多关联update的SQL语句

MYSQL: http://www.111cn.net/database/mysql/45963.htm
1. update table_1 set score = score + 5 where uid in (select uid from table_2 where sid = 10);
===>等价于===>
update table_1 t1 inner join table_2 t2 on t1.uid = t2.uid set score = score + 5 where t2.sid = 10;

2.
UPDATE Track
INNER JOIN MV
ON Track.trkid=MV.mvid
SET Track.is_show=MV.is_show
WHERE trkid<6

等同于

UPDATE Track,MV
SET Track.is_show=MV.is_show
WHERE Track.trkid=MV.mvid and trkid<6

更多条件
update PSI_WAREHOUSE_IO_RECORD t1 
inner join PSI_SUPPLY_ORDER_DETAIL t2 on t1.P_ORDER_DETAIL_ID = t2.ORDER_DETAIL_ID 
inner join PSI_SUPPLY_GOOD t3 on t2.SUPPLY_GOOD_ID = t3.SUPPLY_GOOD_ID 
set t1.GOOD_ID = t3.GOOD_ID, t1.P_ORDER_ID = t2.SUPPLY_ORDER_ID, t1.SUPPLY_ID = t2.SUPPLY_ID WHERE t1.IO_TYPE='SUPPLY';



ORACLE 多表关联 UPDATE 语句 http://it.oyksoft.com/post/641/


postgres 多表查询更新 http://liubl2011.iteye.com/blog/1985562
更新一张表a的内容关联其他表作为条件:
Sql代码  收藏代码
update a set name='xx'  
from t1 t1,t2 t2 
where t1.age=t2.age 
t1.name = a.name 


第二种比较小白我以前的做法
Sql代码  收藏代码
update tc set task_code = 'xxxx' 
WHERE  
task_code = 'xxxxx2' 
AND exists ( 
select cust_code FROM alc 
WHERE district_code = 'aa' 
AND cust_code = tc.cust_code 
AND cust_sample_flag = '1' 

sql server多表关联update
UPDATE Tab1 SET a.Name = b.Name FROM Tab1 a,Tab2 b WHERE a.ID = b.ID

猜你喜欢

转载自panyongzheng.iteye.com/blog/2229667