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
                )
相关推荐
AI题库12 分钟前
PostgreSQL 18 从新手到大师:实战指南 - 2.4 备份与恢复策略
数据库·postgresql·oracle·数据库备份
晴天¥14 分钟前
Oracle中的概要文件
运维·数据库·oracle
一 乐31 分钟前
健康管理|基于springboot + vue健康管理系统(源码+数据库+文档)
java·前端·数据库·vue.js·spring boot·后端·学习
学编程就要猛34 分钟前
MySQL:CRUD
数据库·sql·mysql
IT技术分享社区34 分钟前
MySQL实战:自动计算字段如何让查询效率翻倍?
数据库·mysql
Live&&learn1 小时前
Redis语法入门
数据库·redis
我就是你毛毛哥1 小时前
Linux 定时备份 MySQL 并推送 Gitee
linux·mysql
未羽出衫1 小时前
DB-GPT本地模型+tuGragh安装使用
数据库·gpt
忧郁蓝调261 小时前
Redis不停机数据迁移:基于 redis-shake 的跨实例 / 跨集群同步方案
运维·数据库·redis·阿里云·缓存·云原生·paas
VekiSon1 小时前
数据库——基础概念与 SQLite 实践
数据库·sqlite