单独看看 select t1.yj,t2.dep from table1 t1 right join table2 t2 on t1.dep=t2.dep
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='一月份'这两个不一样吗 从语法看一样吧 结果却不一样
有就行了 t1.dep(+)=t2.dep 写法已经很老的 现在还用那个
关键是结果不一样啊 第一个现实的是table2的所有信息 而另一个不是
select t1.yj,t2.dep from table1 t1 right join table2 t2 on t1.dep=t2.dep where t1.mon='一月份'
试试这个: select t1.yj,t2.dep from table1 t1,table2 t2 where t1.mon(+)='一月份' and t1.dep(+)=t2.dep 用(+)做外连接时,在where条件中所有该表的字段都需要加上(+)(包括常量)
select t1.yj,t2.dep from (SELECT * FROM table1 WHERE mon='一月份') t1,table2 t2 WHERE t1.dep(+)=t2.dep
我觉得写SQL在连接的时候用(+)很好啊 为什么说很老了呢!
呵呵,省事,不过是oracle的土格式,不是sql标准规范
两个语句的查询结果某些情况下可能是不一样的。 假如 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
select t1.yj,t2.dep from table1 t1 right join table2 t2 on t1.dep=t2.dep
and t1.mon='一月份'这两个不一样吗 从语法看一样吧 结果却不一样
t1.dep(+)=t2.dep 写法已经很老的 现在还用那个
where t1.mon='一月份'
select t1.yj,t2.dep from table1 t1,table2 t2 where t1.mon(+)='一月份' and t1.dep(+)=t2.dep
用(+)做外连接时,在where条件中所有该表的字段都需要加上(+)(包括常量)
假如
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