oracle中两张表:
table1,table2其中table1:
   A1         A2          A3
 20011      20022        20033
 20013      20021        20031
           ......table2:
  code         name
 20011         北京
 20013         天津
 20022         上海
 20033         重庆
           ...... 现在需要一条语句将table1中A1、A2、A3具体的名称查询出来,我写了select t1.a1,t1.a2,t1.a3,df,name from table1 t1,table2 df where t1.a1=df.code(+) and t1.a2=df.code(+) and t1.a3=df.code(+)但是执行后,如果table1中的a1、a2、a3相同的话可以得出数据,不同的话就得不出数据,将where 后的and改成or 反馈不能在外连接符中用‘or’和‘in’,把(+)去掉,结果什么也查不出来!
望高手指点!

解决方案 »

  1.   

    试试这个
    select t1.a1,t1.a2,t1.a3,df,name 
    from table1 t1,
    table2 df,
    table2 t2,
    table3 t3
    where t1.a1=df.code(+) and t1.a2=t2.code(+) and t1.a3=t3.code(+)
      

  2.   

    不明白什么意思,“select t1.a1,t1.a2,t1.a3,df,name from“,df是table2,根本就不能执行 。如果是df.name,不可能三个都显示阿。
    楼上更强,table3都出来了
    。。
      

  3.   

    select t.A1,t1.name,t.A2,t2.name,t.A3,t3.name
      from table1 t,table2 t1,table2 1,table2 t3
     where t.A1 = t1.code(+)
       and t.A1 = t2.code(+)
       and t.A1 = t3.code(+)
      

  4.   

    不好意思,写错了,应该是“df.name”
    感谢上面的朋友,我的问题解决了,和shui_windows() 的方法一样,比较苯,但比较直观,具体是这样的:将table2表明三个不同的别名,查询时就可以当成三张不同的表了select df1.name,df2.name,df3.name from table1 t1,table2 df1,table2 df2,table2 df3 where t1.a1=df1.code(+) and t1.a2=df2.code(+) and t1.a3=df3.code(+)
    这样查询出来的结果就正确了,但是不知道效率是不是较低,因为数据量不大,也看不出了,看看大家还有什么更好的方法!