MySQL关联left join 条件on与where不同
来源:互联网 发布:u盘照片数据恢复 编辑:程序博客网 时间:2024/05/24 05:51
联表查询的on个where 语句 文章来源:http://database.51cto.com/art/201005/200521.htm(尊重别人劳动成果)
http://bbs.csdn.net/topics/390582391(这个链接有图 可以更详细的分析)
自己总结:先写个sql对比
a: select p.pname,p.pcode,s.saletime,count(s.aid) as total from products as p
left join sales_detail as s on (s.pcode=p.pcode)
where s.saletime in ('2008-09-23','2008-09-24')
group by p.pcode order by total desc,p.pid asc
b:select p.pname,p.pcode,s.saletime,count(s.aid) as total from products as p
left join sales_detail as s on ((s.pcode=p.pcode)
and s.saletime in ('2008-09-23','2008-09-24'))
group by p.pcode order by total desc,p.pid asc
表结构这里就不写了 直接看查询的结果就知道了
pname | pcode | saletime | total | -----第一个语句
| 商品1 | AC90 | 2008-09-23 | 2 |
pname | pcode | saletime | total | -----第二个语句
| 商品1 | AC90 | 2008-09-23 | 2 |
| 商品2 | DE78 | NULL | 0 |
| 商品3 | XXXX | NULL | 0 |
分析下明白 : on、and 中的条件关联,一表数据不满足条件时会显示空值。where则输出两表完全满足条件数据。
from 表1 left on 表2 on后面的条件判断全部是针对left join的表 where 针对2张表
- MySQL关联left/right+join+on条件与where不同
- MySQL关联left join 条件on与where不同
- MySQL关联left join 条件on与where不同
- MySQL关联left join 条件on与where不同
- MySQL关联left join 条件on与where不同
- MySQL关联left join 条件on与where不同
- MySQL关联left join 条件on与where不同
- MySQL关联left join 条件on与where不同,很实用,但要慎用
- MySql Left join on 与 where比较
- left join加上on条件与where条件区别
- Mysql Left Join Where On
- Mysql Left Join Where On
- MySQL left join操作中 on与where放置条件的区别
- Left Join...ON与Where
- mysql join on 后面条件与where条件
- mysql中left(right)join之on与where
- mysql 中left join on 与 where 的区别
- MySQL的left join中on与where的区别
- C++ 中使用json
- [FastDFS] tracker报错, ERROR - file: tracker_nio.c, line: 214, recv timeout
- PATB1020
- 单机数据库调整redo log日志大小
- Markdown 常用语法简单学习
- MySQL关联left join 条件on与where不同
- iOS内存管理之:引用计数、ARC、自动释放池autoreleasepool和便捷方法之间的关系
- Python压缩多个属于不同驱动器的文件夹至同一个zip文件
- Windows PowerShell中scp命令
- wget/curl回源请求带host
- 自己写的日志框架--linkinLog4j--框架可配置+提性能
- Swift iOS tableView static cell动态计算高度
- linux-shell-#@!...
- Linux查看程序端口占用情况