有表a,字段为code,ordernumber,count字段 code为关键字段
表b,字段为id,code,ordernumber,count字段,其中id为自动类加。为关键字段。
表a实例:
00001 sa001  3.12    
00002 sa001  5.20
00003 sa001  4.11
00004 sa002  4.50
00005 sa002  8.38
00006 sa003  9.00
表b实例:
1 00006 sa003  4.00
2 00006 sa003  5.00
要从这两张表中select出个集合,如下:
sa001  3.12    
sa001  5.20
sa001  4.11
sa002  4.50
sa002  8.38
sa003  4.00
sa003  5.00
怎么select?
(也就是表a中00006的数据不能显示,要用表b中的数据代替)

解决方案 »

  1.   

    select code,ordernumber,count
    from a
    where not exists(select 1
                     from b
                     where b.code=a.code
                     )
    union all
    select code,ordernumber,count
    from b你试一下,这样行吗?
    不行再发消息给我。
    (我现在没有环境测试)
      

  2.   

    SELECT ordernumber,count
    FROM a
    WHERE code not in (SELECT code FROM b)
    UNION
    SELECT ordernumber,count
    FROM b
      

  3.   

    你试一下这个语句:select ordernumber,count from 表a,表b
                    where 表a.code<00006
      

  4.   

    楼上zhoutian618,在oracle 下通过验证是正确的。
    真得好好学习一下
      

  5.   

    select code,ordernumber,count
    from a
    where not code in (select code from b )
    union all
    select code,ordernumber,count
    from b