select t1.yj,t2.dep from table1 t1,table2 t2 where t1.mon='一月份' and t1.dep(+)=t2.dep
为什么 t2表中的04部门没有显示出来 我用的是右外连接啊 table2表中部门编号不是都该显示出来吗

解决方案 »

  1.   

    单独看看
    select t1.yj,t2.dep from table1 t1 right join table2 t2 on t1.dep=t2.dep
      

  2.   

    select t1.yj,t2.dep from table1 t1 right join table2 t2 on t1.mon='一月份' and t1.dep=t2.depselect t1.yj,t2.dep from table1 t1,table2 t2 where  t1.dep(+)=t2.dep 
    and  t1.mon='一月份'这两个不一样吗 从语法看一样吧 结果却不一样
      

  3.   

    有就行了 
     t1.dep(+)=t2.dep 写法已经很老的 现在还用那个
      

  4.   

    关键是结果不一样啊 第一个现实的是table2的所有信息 而另一个不是
      

  5.   

    select t1.yj,t2.dep from table1 t1 right join table2 t2 on t1.dep=t2.dep
    where t1.mon='一月份'
      

  6.   

    试试这个:
    select t1.yj,t2.dep from table1 t1,table2 t2 where t1.mon(+)='一月份' and t1.dep(+)=t2.dep
    用(+)做外连接时,在where条件中所有该表的字段都需要加上(+)(包括常量)
      

  7.   

    select t1.yj,t2.dep from (SELECT * FROM table1 WHERE mon='一月份') t1,table2 t2 WHERE  t1.dep(+)=t2.dep
      

  8.   

    我觉得写SQL在连接的时候用(+)很好啊 为什么说很老了呢!
      

  9.   

    呵呵,省事,不过是oracle的土格式,不是sql标准规范
      

  10.   

    两个语句的查询结果某些情况下可能是不一样的。
    假如
    T1内有三条数据
    1
    2
    3
    T2内有两条数据
    1
    2select t1.yj,t2.dep from table1 t1 right join table2 t2 on t1.mon='一月份' and t1.dep=t2.depselect t1.yj,t2.dep from table1 t1,table2 t2 where t1.dep(+)=t2.dep  
    and t1.mon='一月份'第一条语句结果只有1和2两条数据
    第二条会有三条语句。
    第一条语句结果只要两表内都有的数据。相当于JION语句
    第二条语句以T1表的数据为基准,就是说会有三条记录返回。相当于LEFT JOIN