多关联update的SQL语句
MYSQL: http://www.111cn.net/database/mysql/45963.htm 这里很详细: https://blog.csdn.net/wslyy99/article/details/4336602
1.
1.
1 2 3 |
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; |
例子:
1 |
update CORE_SHIRO_USER t1 inner join PSI_USER_STAFF t2 on t1.USER_ID = t2.USER_ID set t1.RELA_TYPE='PSI',t1.RELA_ID = t2.STAFF_ID; |
2.
1 2 3 4 5 6 7 |
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 |
更多条件
ORACLE 多表关联 UPDATE 语句 http://it.oyksoft.com/post/641/
postgres 多表查询更新 http://liubl2011.iteye.com/blog/1985562
更新一张表a的内容关联其他表作为条件:
1 2 3 4 |
update a set name='xx' from t1 t1,t2 t2 where t1.age=t2.age t1.name = a.name |
第二种比较小白我以前的做法
1 2 3 4 5 6 7 8 9 |
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
1 |
UPDATE Tab1 SET a.Name = b.Name FROM Tab1 a,Tab2 b WHERE a.ID = b.ID |