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后面则是对主表与辅表关联后结果集再进行过滤。
相关推荐
l1t12 分钟前
DeepSeek总结的DuckLake 入门
数据库
Joseph Cooper21 分钟前
RAG 与 AI Agent:智能体真的需要检索增强生成吗?
数据库·人工智能·ai·agent·rag·上下文工程
light blue bird24 分钟前
主子端台二分法任务汇总组件
前端·数据库·.net·桌面端winform
DevilSeagull1 小时前
MySQL(2) 客户端工具和建库
开发语言·数据库·后端·mysql·服务
小李来了!1 小时前
Navicate/plsql连接Oracle数据库教程
数据库·oracle
苍煜1 小时前
慢SQL优化实战教学
java·数据库·sql
zhaoyong2222 小时前
MySQL 存储过程中字符集与排序规则不匹配导致查询性能下降的解决方案
jvm·数据库·python
sinat_383437362 小时前
golang如何从Python转型Go开发_golang从Python转型Go开发攻略
jvm·数据库·python
远洪2 小时前
claude code 国内安装使用
数据库·mysql
雨辰AI2 小时前
SpringBoot3 + 人大金仓 V9 微服务监控实战|Prometheus+Grafana+SkyWalking 全链路监控
数据库·后端·微服务·grafana·prometheus·skywalking