不灭的焱

革命尚未成功,同志仍须努力下载JDK17

作者:Albert.Wen  添加时间:2023-04-02 18:21:35  修改时间:2024-04-30 12:24:34  分类:MySQL/Redis  编辑

SQL 查询出 重复的数据:保留 id 最大值的记录

本地测试 案例

(1)查询 重复数据:

select a.* from "albert_test_a" a where exists (select b.* from "albert_test_a" b where b."email" = a."email" and b.id> a.id)

(2)删除 重复数据:

delete from "albert_test_a" a where exists (select b.* from "albert_test_a" b where b."email" = a."email" and b.id> a.id)

 


 

织信低代码系统  案例

(1)查询 重复数据:

select a.* from "z_0Z6t6t3lczX7fhcH" a where exists (select b.* from "z_0Z6t6t3lczX7fhcH" b where b."0Z6t6t3eN2K8U1Yj" = a."0Z6t6t3eN2K8U1Yj" and b.row_number > a.row_number)

(2)删除 重复数据:

delete from "z_0Z6t6t3lczX7fhcH" a where exists (select b.* from "z_0Z6t6t3lczX7fhcH" b where b."0Z6t6t3eN2K8U1Yj" = a."0Z6t6t3eN2K8U1Yj" and b.row_number > a.row_number)