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后面则是对主表与辅表关联后结果集再进行过滤。
相关推荐
ClouGence18 小时前
Oracle CDC 架构优化:从主库直连到 DataGuard 备库同步
数据库·后端·oracle
无响应de神20 小时前
三、用户与权限管理
数据库·mysql
麦聪聊数据2 天前
数据服务化时代:企业数据能力输出的核心路径
数据库
shushangyun_2 天前
2026年快消品B2B系统推荐:支持终端门店订货、促销政策自动化的工具?
java·运维·网络·数据库·人工智能·spring·自动化
DARLING Zero two♡2 天前
【MySQL数据库】数据类型与表约束
数据库·mysql
曹牧2 天前
Oracle EXPLAIN PLAN
数据库·oracle
BD_Marathon2 天前
SQL学习指南——视图
数据库·sql
活宝小娜2 天前
mysql详细安装教程
数据库·mysql·adb
贤时间2 天前
codex 助力oracle ebs 开发
数据库·oracle
秉承初心2 天前
PostgreSQL 数据性能瓶颈突破实战
数据库·postgresql·oracle