oracle的sql语句写法——涉及两个表的字段更新

update info_user i set (i.name) = (select d.name from data_user_info d where d.id = i.id)
where i.id = (select d.id from data_user_info d where d.id = i.id);
这种写法肯定行,可是set后面接了一大串内容,看起来很乱,有没有简单的写法?

第1个回答  2013-07-25
oracle 没有 update from 的语法,替代的写法就是:

update info_user i
set i.name = (select d.name from data_user_info d where d.id = i.id) -- 从data_user_info中取名称,条件是两者id 相等
where exists (select 1 from data_user_info d where d.id = i.id) -- 仅仅当data_info_user中有和info_user一致的id,才对info_user的数据更新追问

这个和我的有什么区别。。。

追答

其实一样,不过我这段时间 习惯 了exists 的写法。

追问

呵呵。。。其实我也用的exists。。。

追答

原先不太会用 exists ,习惯用 in ,也不习惯用你的 = 。

追问

上面那个兄弟太敬业了。不给他最佳答案我都过意不去了。。。

追答

想敬业的人致敬!!!

相似回答