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

avatar
作者
猴君
阅读量:1

不去重状态

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                 )

广告一刻

为您即时展示最新活动产品广告消息,让您随时掌握产品活动新动态!