mysql left join on 与 where 筛选的差异
来源:互联网 发布:js正则判断是否是数字 编辑:程序博客网 时间:2024/06/15 11:25
mysql left join on 与 where 筛选的差异
准备两张表:
a表:id a1 a12 a23 a3b表:id b1 b12 b2
1.没有条件
SELECT * FROM a
LEFT JOIN b ON a.id = b.id;
------------------------------
id a id1 b
1 a1 1 b1
2 a2 2 b2
3 a3
2.WHERE
SELECT * FROM a
LEFT JOIN b ON a.id = b.id
WHERE b.b = 'b1';
------------------------------
id a id1 b
1 a1 1 b1
3.ON(AND)
SELECT * FROM a
LEFT JOIN b ON a.id = b.id
AND b.b = 'b1';
------------------------------
id a id1 b
1 a1 1 b1
2 a2
3 a3
发现left join 语句 on和 where有差异,
和标准查询关键字执行顺序有关;
left join 是在from范围类,所以先on条件筛选表,然后两表再做left join。
而对于where来说在left join结果再次筛选
where等价于:
1>SELECT * FROM a LEFT JOIN b ON a.id = b.id;
2>在查询结果中将b.b = 'b1'筛选出来
on(and)等价于:
1>select * from b where b.b = 'b1'
2>再将查询结果与A表做left join
*********************************************
* 对于主表的筛选条件应放在where后面
* 对于关联表的筛选条件应放到on后面
SELECT * FROM a
LEFT JOIN (SELECT * from b where b.b = 'b1') b ON a.id = b.id
where a.a = 'a1';
2 0
- mysql left join on 与 where 筛选的差异
- mysql left join on 与 where 筛选的差异
- mysql left join on 与 where 筛选的差异
- mysql left( right ) join使用on 与where 筛选的差异。mysql的执行顺序
- 【mysql】mysql中left join使用on 与where筛选的差异
- mysql left( right ) join使用on 与where 筛选的差异
- mysql left( right ) join使用on 与where 筛选的差异
- mysql left( right ) join使用on 与where 筛选的差异
- mysql left( right ) join使用on 与where 筛选的差异
- mysql left( right ) join使用on 与where 筛选的差异
- mysql left( right ) join使用on 与where 筛选的差异
- mysql left( right ) join使用on 与where 筛选的差异
- mysql left( right ) join使用on 与where 筛选的差异
- mysql left( right ) join使用on 与where 筛选的差异 博客分类: mysql MySQLSQL数据结构 有这样的一个问题mysql查询使用mysql中left(
- mysql left join的on和where的差异
- MySql Left join on 与 where比较
- MySQL的left join中on与where的区别
- mysql 中left join on 与 where 的区别
- 【8】机器学习之屠龙宝剑:GBDT
- laravel运行composer update时出现如下错误信息的解决方案
- 属性
- 用Eclipse和GDB构建ARM交叉编译和在线调试环境
- Single Number III
- mysql left join on 与 where 筛选的差异
- Linux上用udev自动识别并挂载U盘
- java设计模式之代理模式
- SwipeRefreshLayout在onCreate使用setRefreshing(true)无效
- Odoo 8项目管理Project Management使用图文介绍
- 冒泡排序
- 分布式中的一致性模型
- House Robber II 如何获得最大的钱系列2
- 获取当前版本信息