as400 update语句 问题

1、************************************************我新建了两张物理表,tab_1,tab_2,其中它们的数据分别为tab_1------------------------------------bm   mc          value1     value201  &nbs...显示全部
1、************************************************
我新建了两张物理表,tab_1,tab_2,其中它们的数据分别为
tab_1
------------------------------------
bm   mc          value1     value2
01   01编码        0          0
02   02编码        0          0
03   03编码        0          0
------------------------------------
tab_2
------------------------------------
bm   mc          value1
01   01编码        100         
------------------------------------
2、************************************************
然后我使用update语句
update tab_1 a set value1 = (select value1 from tab_2 b where a.bm=b.bm);
3、************************************************
可是最后查询结果却是这样
select * from tab_1;
tab_1
------------------------------------
bm   mc          value1     value2
01   01编码        100         0
02   02编码         -          0
03   03编码         -          0
------------------------------------
为02,03编码的value1值变成空值了。
select * from tab_1 where value1 is null;
tab_1
------------------------------------
bm   mc          value1     value2
02   02编码         -          0
03   03编码         -          0
------------------------------------收起
参与10

查看其它 6 个回答db2_wl的回答

db2_wldb2_wl系统工程师weall
问题解决了,在后面加上where条件就好了
update tab_1 a set value1 = (select value1 from tab_2 b where a.bm=b.bm)
where a.a1 in(select c.a1 from t1 c);
政府机关 · 2011-03-21
浏览1061

回答者

db2_wl
系统工程师weall
擅长领域: 数据库

回答状态

  • 发布时间:2011-03-21
  • 关注会员:2 人
  • 回答浏览:1061
  • X社区推广