你的需求说的不是很明确,两个字段的code是关联吗?要显示全部记录吗? select a.type,a.code,b.name from a,b where a.code=b.code

解决方案 »

  1.   

    同上!select a.type,a.code,b.name from a,b where a.code=b.code(+)
    union
    select a.type,a.code,b.name from a,b where a.code(+)=b.code
      

  2.   

    是的,A.code和B.code是一个东西,应该需要关联。dinya2003(OK)和zhpsam109(孤寂无边)的解法有什么不同?
    例如b.code(+)中的(+)表示什么意思?
      

  3.   

    (+)表示外连接
    9i,sql server中的left outer join /right outer join;
      

  4.   

    有個問題要說清楚,是不是a/b的全部數據都要?還是要A/B都有的數據?還是要A或B表中所有的?
      

  5.   

    inner join
    or
    full outer join
      

  6.   

    两个表中的数据都要出来。
    我试了一下,是不是要加DISTINCT?否则会出现重复数据?
      

  7.   

    select DISTINCT type,code,name
    from
    (
    select a.type,a.code,b.name from a,b where a.code=b.code(+)
    union
    select a.type,a.code,b.name from a,b where a.code(+)=b.code
    )
      

  8.   

    select distinct a.type,a.code,b.name from a,b where a.code=b.code
    如果你得表中可能又重复数据,加上distinct
      

  9.   

    用union 啊
    很简单的。
      

  10.   

    union自动会删除重复记录的,所以不需要用distinct,除非你用union all