Oracle左连接过滤条件注意事项

1、left join 结果集行数与主表查询结果集行数一致

2、主表与辅表多关联条件要括起来

3、对于辅表的过滤条件写在on后面是先对辅表过滤后再与主表关联,写在where后面是对主表与辅表关联后的结果集再进行过滤

4、对于主表的过滤条件写在on后面不生效,只能写在where后面

例如:

java 复制代码
select t.t1,
	listagg(d.d2,',')  as d2s 
	from table1 t
	left join table2 d
	on (t.t1 = d.d1 and t.t2 = d.d2 and d.status in ('0','1'))
	where t.status='3'
	and t.roleid in ('roleA','roleB')
	and t.orgcode in ('3500')
group by t.t1

d.status in ('0','1')过滤条件写on后面是先对表d过滤缩小范围后再与主表关联,若写在where后面则是对主表与辅表关联后结果集再进行过滤。
相关推荐
悄悄敲敲敲7 小时前
MySQL表的约束
数据库·mysql
鼠爷ねずみ7 小时前
SpringCloud前后端整体开发流程-以及技术总结文章实时更新中
java·数据库·后端·spring·spring cloud
九皇叔叔8 小时前
MySQL 数据库 Read View 详解
数据库·mysql·mvcc·read view
Elastic 中国社区官方博客9 小时前
Elasticsearch:圣诞晚餐 BBQ - 图像识别
大数据·数据库·elasticsearch·搜索引擎·ai·全文检索
cui_win9 小时前
Prometheus实战教程 - Redis 监控
数据库·redis·prometheus
JIngJaneIL10 小时前
基于java + vue个人博客系统(源码+数据库+文档)
java·开发语言·前端·数据库·vue.js·spring boot
TG:@yunlaoda360 云老大10 小时前
华为云国际站代理商备份策略设置过程中遇到问题如何解决?
服务器·数据库·华为云
SelectDB10 小时前
Doris Catalog 已上线!性能提升 200x,全面优于 JDBC Catalog,跨集群查询迈入高性能分析时代
数据库·数据分析·apache
TAEHENGV10 小时前
进度跟踪模块 Cordova 与 OpenHarmony 混合开发实战
android·javascript·数据库
神秘面具男0310 小时前
MySQL 从基础到实践
数据库·mysql