现有 表 A 字段为 a1 ,a2,a3,a4 主键为 a1
表B 字段跟A一样,但是表B 只有表A的部分数据(表B中的a1全部来自A表),
现在表B的a4 字段有做修改,
如何用B表中的a4来修改A中的a4字段
现在用的语句如下:
update A t set t.a4 =(select b.a4 from B where A.a1=B.a4)
where A.a1 in (select b.a1 from B where A.a1=B.a4) ;
总觉得这条语句有点怪,但是 又不能删除where 条件 ,否则 如果A表中a1不在B表中的数据的所有a4将变为空
表B 字段跟A一样,但是表B 只有表A的部分数据(表B中的a1全部来自A表),
现在表B的a4 字段有做修改,
如何用B表中的a4来修改A中的a4字段
现在用的语句如下:
update A t set t.a4 =(select b.a4 from B where A.a1=B.a4)
where A.a1 in (select b.a1 from B where A.a1=B.a4) ;
总觉得这条语句有点怪,但是 又不能删除where 条件 ,否则 如果A表中a1不在B表中的数据的所有a4将变为空
你看这个行不行
update A
set A.a4 =
(select B.a4
from B
where B.a1 = A.a1)
where exists
(select '1'
from B
where A.a1 = B.a1);
from a
join b on a.a1 = b.a1 and a.a4 <> b.a4
你到B表中去查询t(A)的字段t.a3,能够行吗???????
select nvl(b.a4,t.a3) from B b where t.a1 = b.a1
exists (select 1 from B where A.id=B.id);
2 [color=#808000]update A set A.name = nvl((select B.name from B where A.id=B.id),A.name);[/color] 这两种方式都能实现,但是发现更新的行数,还是有所不同的,第一种是只更新查到的不同的数据
;第二种更新了全部,就是说即使数据B中没有A的数据,A中还会在进行一次自我更新.
所以效率第二种高
1 update A set A.name=(select B.name from B where A.id=B.id) where
exists (select 1 from B where A.id=B.id);
2 update A set A.name = nvl((select B.name from B where A.id=B.id),A.nam……
所以效率第一种高