left join条件写在on中和where中的区别
来源:互联网 发布:js三级联动菜单 编辑:程序博客网 时间:2024/06/02 13:12
create table t1(id int, feild int);
insert into t1 values(1 , 1);
insert into t1 values(1 , 2);
insert into t1 values(1 , 3);
insert into t1 values(1 , 4);
insert into t1 values(2 , 1);
insert into t1 values(2 , 2);
create table t2(id int, feild int);
insert into t2 values(1 , 1);
insert into t2 values(1 , 2);
insert into t2 values(1 , 5);
insert into t2 values(1 , 6);
insert into t2 values(2 , 1);
insert into t2 values(2 , 3);
select t1.*,t2.* from t1 left join t2 on t1.id=t2.id
--取t1表的第一行,扫瞄t2表,按条件做对比,如果满足条件,就加入返回结果表.
然后取t1表的第二行,扫瞄t2表,按条件做对比,如果满足条件,就加入返回结果表.
重复以上过程,直到t1表扫描结束.
select t1.*,t2.* from t1 left join t2 on t1.id=t2.id and t1.feild=1
--给左表加条件的时候,左表满足条件的,按上面的过程返回值,左表不满足条件的,直接输出,右表的列补null
select t1.*,t2.* from t1 left join t2 on t1.id=t2.id where t1.feild=1 先执行where后连接查询
执行where后表为 1 , 1
2 , 1
用它来left join t2.
--下面三条语句查询结果是一样的
select t1.*,t2.* from t1 left join t2 on t1.id=t2.id and t2.feild=1
select t1.*,t2.* from t1 left join t2 on t1.id=t2.id where t2.feild=1
select t1.*,t2.* from t1 inner join t2 on t1.id=t2.id and t2.feild=1
- left join条件写在on中和where中的区别
- LEFT JOIN(联表)的条件写在ON中和WHERE的区别
- left join 过滤条件写在on后面和写在where 后面的区别
- left join 过滤条件写在on后面和写在where 后面的区别
- left join加上on条件与where条件区别
- left join on、where后面的条件的区别
- left join (on 和 where条件放置的区别)
- left join on、where后面的条件的区别
- left join on 和where条件的放置 区别
- left join (on 和 where条件放置的区别)
- left join(on和where条件放置的区别)
- left join、inner join中的on与where的区别
- left join,right join,inner join的条件on和where的区别
- left jion中的on和where条件中的区别
- Oracle LEFT JOIN中ON条件与WHERE条件的区别
- left join on后的条件与where后的条件的区别
- left join on后面 加条件和where后面加条件的区别
- SQL Server: left join on 和 left join where区别
- ibatis中传递多个参数
- 定时任务组件使用经验介绍
- 【Windows】查看电脑的开关机时间
- dijkstra算法--刚学
- 表信息重复处理
- left join条件写在on中和where中的区别
- Merge Sort
- ubuntu10.10嵌入式boa web服务器移植
- 网络推广员的苦恼
- Android中怎么让你的layout适应屏幕的大小
- 【Windows】虚拟内存设置
- unicode UTF-8 GBK GB2312 之间的区别和关系
- 【Windows】Windows7下游戏全屏问题通用解决方法
- 仿腾讯QQ界面