SQL 多变关联使用子查询去重

不去重状态

复制代码
select a.*,
       b.recon_amt
from free_settlement_first a
         left join free_settlement_second b on a.settlement_first_id = b.settlement_first_id

有2条数据出现了重复

使用子查询去重

复制代码
select a.*,
       b.recon_amt
from free_settlement_first a
         left join free_settlement_second b on a.settlement_first_id = b.settlement_first_id
where not exists(select 1
                 from free_settlement_second b2
                 where a.settlement_first_id = b2.settlement_first_id
                   and b.settlement_second_id > b2.settlement_second_id
                )
相关推荐
2401_831501738 分钟前
MySQL 知识小结(一)
数据库·mysql
不爱搬砖的码农9 分钟前
windows系统MySQL安装文档
windows·mysql·adb
23级二本计科11 分钟前
14.MySQL用C语言连接
数据库·mysql
运维成长记16 分钟前
Zabbix 高可用架构部署方案(2最新版)
mysql·架构·zabbix
琪阿不会编程17 分钟前
Mysql8 忘记密码重置,以及问题解决
android·数据库·sql·mysql
Villiam_AY30 分钟前
redis主从复制
数据库·redis·缓存
955.40 分钟前
tomcat+mysql电商实战项目毕业设计
mysql·tomcat·课程设计
甜甜的资料库1 小时前
基于微信小程序的作业管理系统源码数据库文档
java·数据库·微信小程序·小程序
甜甜的资料库1 小时前
基于微信小程序的车位共享平台的设计与实现源码数据库文档
数据库·微信小程序·小程序
why1517 小时前
微服务商城-商品微服务
数据库·后端·golang