两表关联更新的语句为:
update table1 set name=(select from table2 where table1.id=table2.id)
where exists (select 1 from table2 where table1.id=table2.id);
我一般在两表关联更新时是这样写的:
update table1 set name=(select from table2 where table1.id=table2.id)
没有后面的where语句,不知道加了后面的条件语句以后有什么好处呢?
如果涉及多表更新呢?
update table1 set
name1 = (select table2_field2 from table2 where table2.id = table1.id),
name2 = (select table3.field3 from table3 where table3.id = table1.id)
.....................
如果上面的语句要从多张表中取数据,然后更新多个字段时,该如何写?分开写,还是写成一句?
各有什么好处?
update table1 set name=(select from table2 where table1.id=table2.id)
where exists (select 1 from table2 where table1.id=table2.id);
我一般在两表关联更新时是这样写的:
update table1 set name=(select from table2 where table1.id=table2.id)
没有后面的where语句,不知道加了后面的条件语句以后有什么好处呢?
如果涉及多表更新呢?
update table1 set
name1 = (select table2_field2 from table2 where table2.id = table1.id),
name2 = (select table3.field3 from table3 where table3.id = table1.id)
.....................
如果上面的语句要从多张表中取数据,然后更新多个字段时,该如何写?分开写,还是写成一句?
各有什么好处?
解决方案 »
- SQL 语句求助
- oracle存储过程调用java代码的问题
- 一行三列转换成三行一列的简单sql语句,解决就给分
- oracle 11g s2 安装问题!急。。。
- 求一SQL语句,急,在线等候!ORACLE9I!谢谢
- 急:oracle 9i 在win2000server上怎么打补丁??有谁知道,不胜感激!
- Orcale中数据同步的问题
- 请教各位高手!!!很急!!!!!!!!!!!!!!!!!!!
- 急急急!!!在Orcale中GBK大字符集无法存入!!请求高手解决!!!
- 使用OCI的OCIStmtExecute()查询一个select语句,用时10秒,不知那位大虾能告知原因。散分100。
- 急!用recover database until time恢复数据库出错
- 建表的语法问题,请关注!
update table1 set
field1 = (select field1 from table2 where table2.id=table1.id),
field2 = (select field2 from table2 where table2.id=table1.id),
field3 = (select field3 from table2 where table2.id=table1.id),
field4 = (select field4 from table2 where table2.id=table1.id)
就只有上面的那种写法吗?有没有简洁一点的写法?另外此时加上where子句时有什么好处?
where exists (select 1 from table2 where table1.id=table2.id);
update table1 set field1,field2,field3..fieldn=(select field1,field2,field3..fieldn from table2 where table1.id=table2.id)