现在有两个表A和B
A 的结构为
no jg
1 12
2 15
3 4 
4 3
5 4
B的结构为
no jg
2 9
4 5
我想用B表的jg字段的数据覆盖A表中的字段no与B表的no字段相同的ig字段的内容,请问怎么做啊?

解决方案 »

  1.   

    update A set jp=(select jp from B where no=A.no)
    where exists (select 1 from B where no=A.no)
      

  2.   

    楼上的写法是正确的啊,现在有一个问题:
    update a set jg=(select jg from b where no=a.no) where exists (select 1 from b where no=a.no);
    这样写的话没有问题,但是
    update a set jg=(select jg from b where no=a.no) where exists (select 1 from a,b where a.no=b.no);
    这样写的话还是会把a表中存在而b表中不存在的jg置为null,请问这是为什么啊?
      

  3.   

    where exists (select 1 from a,b where a.no=b.no);
    这个条件永远成立
      

  4.   

    可是select 1 from b where no=a.no也是永远成立的啊.
      

  5.   

    SQL> select * from a,b where a.no=b.no;NO         JG         NO         JG
    ---------- ---------- ---------- ----------
    1          10         1          100SQL> select * from a where exists (select * from b where no=a.no);NO         JG
    ---------- ----------
    1          10
    可见两种写法都是返回一行记录的