`

两表(多表)关联update的写法

阅读更多

两表(多表)关联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)

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics