Created
July 24, 2017 14:53
-
-
Save afreeland/8ed9f75c6abc27f58b0ecbe8031fde82 to your computer and use it in GitHub Desktop.
SQL: Remove all duplicates except one
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
with cte as ( | |
select | |
username, | |
start_time, | |
ROW_NUMBER() OVER(Partition by username, start_time order by end_time) as [rn] | |
from sometable | |
) | |
select * from cte | |
--delete cte | |
where [rn] > 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment