问题描述:
我有三个表。表a,b,c,
每一个表都有两个字段,f1,f2;现在是我要用b表中的f1更新表a中的f1;
条件是记录在c表中:即只要b表的f2 = c表的f1 并且 a表的f2 = c表的f2我这样写为何不对:
update a set a.字段1 = b.字段1
from 表a a,表b b ,表c c
where a.字段2 = c.字段1 and b.字段2 = c.字段2
我有三个表。表a,b,c,
每一个表都有两个字段,f1,f2;现在是我要用b表中的f1更新表a中的f1;
条件是记录在c表中:即只要b表的f2 = c表的f1 并且 a表的f2 = c表的f2我这样写为何不对:
update a set a.字段1 = b.字段1
from 表a a,表b b ,表c c
where a.字段2 = c.字段1 and b.字段2 = c.字段2
解决方案 »
- 关于datagridview的问题
- pda下载FTP文件
- c# winform 如何获得http://qq.ip138.com/weather/xinjiang/WuLuMuQi.htm这个网址中的天气预报
- 不能调用委托
- 谁知道firefox?界面是怎么实现的,主题换肤。
- 请教一个关于数据库的问题
- 本人有一书上MRP例子 求共同分析者 留下MSN 谢谢
- 怎样重启线程??
- 请问C#winform打包安装程序时如何将绿色版mysql数据库共同打包并执行数据库所需要的配置以实现用户的一键安装。
- 在线等待:Web端和服务器端是怎么通信的?(菜鸟问题,劳烦大虾们了)
- spread 如何实现联动效果
- C/S 保存登录信息
update (
select yyy.a ya,zzz.b zb,yyy.b yb,zzz.b zb from yyy,zzz where yyy.c = zzz.c;
) set ya=za,yb=zb原理就是关联查询出来的结果作为虚拟表,然后批量update。
局限性:用作关联的字段的值,一定都要是唯一特征的。比如这个字段是某个唯一编码表的外键。
update a set a.f2=b.f2 from a join b on a.f1=b.f1
where exists(select * from c where a.f1=c.f1)但是oracle不支持update 子句中再用from join好像,不知道还是用其他的方法
至于比较土的方法,可以用下面这个,oracle 9i通过update a set a.f2=(select f2 from b where a.f1=b.f1)
where exists(select * from c where a.f1=c.f1) and exists(select * from b where a.f1=b.f1)
update a
set a.字段1 = b.字段1
from 表a a,表b b ,表c c
where a.字段2 = c.字段2 and b.字段2 = c.字段1
set a.f1= (select b.f1
from b b, c c
where b.f2 = c.f1 and a.f2=c.f2)
create table b(f1 int,f2 int);
create table c(f1 int,f2 int);insert into a select 1,1 from dual;
insert into a select 1,2 from dual;
insert into b select 2,1 from dual;
insert into b select 2,2 from dual;
insert into c select 2,2 from dual;update a set f1=(select b.f1 from b,c where b.f2=c.f2 and a.f2=c.f1)
where exists(select 1 from b,c where b.f2=c.f2 and a.f2=c.f1);select * from a;drop table a;
drop table b;
drop table c;
/*返回结果
F1 F2
1 1
2 2
*/
where exists(select * from c where a.f1=c.f1) and exists(select * from b where a.f1=b.f1)
where exists(select 1 from b,c where b.f2=c.f2 and a.f2=c.f1);