两表(多表)关联update的写法_SQL技巧
发布于:软件开发网 来源:互联网 作者:佚名 时间:2009-01-01 点击:157
今天凌晨因为要在数据库里做一些操作,是关于两表关联的update,但语句怎么写都不正确,老是报错,于是心惊肉跳(就怕不能及时完成操作)去查了一下,NND,原来把SQL写成了在SQL Server下面的特有形式,这种语法在Oracle下面是行不通的,急忙改回来,及时完成了任务。顺便也把查到的SQL帖出来,哪天再忘记了,也好在这里找回来:
软件开发网
update customers a
set city_name=(select b.city_name from tmp_cust_city b where b.customer_id=a.customer_id)
where exists (select 1
from tmp_cust_city b
where b.customer_id=a.customer_id
)
-- update 超过2个值
update customers a
set (city_name,customer_type)=(select b.city_name,b.customer_type
from tmp_cust_city b
where b.customer_id=a.customer_id)
where exists (select 1
from tmp_cust_city b
where b.customer_id=a.customer_id
)
这是我在mysql的应用,参考了上面的语法.
update t_wb_worldcup_guess g set username=(select u.name from t_wb_user as u where u.uid=g.userid ) where exists (select 1 from t_wb_user u where u.uid = g.userid)
分享到:
相关推荐
例如: 两表(多表)关联update -- 仅在where字句中的连接 --这次提取的数据都是VIP,且包括新增的,所以顺便更新客户类别 update customers a -- 使用别名 set customer_type='01' --01 为vip,00为普通 where ...
--客户资料表 create table customers ( customer_id number(8) not null, -- 客户标示 city_name varchar2(10) not null, -- 所在城市 customer_type char(2) not null, -- 客户类型 ... ) create ...
UPDATE 表2 SET 表2.C = (SELECT B FROM 表1 WHERE 表1.A = 表2.A) WHERE EXISTS (SELECT 1 FROM 表1 WHERE 表1.A = 表2.A); 尤其注意最后的外层where条件尤为重要,是锁定其批量更新数据的范围。 方法二: ...
主要介绍了SQL update 多表关联更新的实现代码,需要的朋友可以参考下
oracle及sqlserver关联两个数据表进行update,即通过一个表的数据update另一个数据表字段
多个DW进行update时正确的写法(转帖)2010-04-11 19:44这种写法有时候不能全部成功: if dw_1.update()= 1 and dw_2.update()=1 ... then commit; else rollback; end if 正确的写法应该这样: 。。。。
主要介绍了SQLServer批量更新两个关联表数据的方法,提供了2种关联查询与更新语句的使用技巧,具有一定参考借鉴价值,需要的朋友可以参考下
VB 利用UPDATE语句批量更新数据表中的数据 VB 利用UPDATE语句批量更新数据表中的数据
更具客户的需求,编写出客户的sql语句,提供oracle 多线程模板
oracle 多表做update insert语句.docx
在MySQL中,可以在 UPDATE语句 中使用JOIN子句执行跨表更新。MySQL UPDATE JOIN的语法如下: UPDATE T1, T2, [INNER JOIN | LEFT JOIN] T1 ON T1.C1 = T2. C1 SET T1.C2 = T2.C2, T2.C3 = expr WHERE condition 更...
To make sure you're protected by the latest security updates, Google Chrome can automatically update when a new version of the browser is available on your ...
我用for update锁表修改数据,结果一直在执行,原来别人锁表了,导致我无法修改数据,用它能查出锁类型和谁锁的
这种多表JOIN后UPDATE经常用到,正常情况下,都是UPDATE一张表,条件也是一张表,但是有时候条件有其他表的,而且更新时,要更新多张的,都有可能。这个虽然简单,但是需要的时候还是必须要用的。
MySQL锁类型以及查询锁表问题、解锁MySQL中select * for update锁表的范围MySQL中select * for update锁表的问题由
FixUpdate与Update的区别1
删除表不是特别常用,特别是对于存在外键关联的表,删除更得小心。但是在开发过程中,发现Schema设计的有问题而且要删除现有的数据库中所有的表来重新创建也是常有的事情;另外在测试的时候,也有需要重新创建数据库...
update 语句优化
多表更新