如何在不使用distinct
,group by
的情况下从数据库中删除重复的条目
Id. Name age dob
1. b. 11. 1992
2. d. 14. 1967
3. b. 11. 1992
答案 0 :(得分:1)
您可以尝试以下操作: 假设test是您的表名:-
delete th
from test as th
where th.id IN (select id
from (select a.id
from test as a
left join test as b
on a.name = b.name where a.id>b.id) AS T);
答案 1 :(得分:1)
您提到使用Name
基于ROW_NUMBER()
进行重复输入时,可以不用DISTINCT
和GROUP BY
。
查询将是:
DELETE FROM (
SELECT Id, ROW_NUMBER() OVER(PARTITION BY Name ORDER BY Id) AS RN
FROM Table
) AS Q
WHERE RN = 1