Skip to content

Instantly share code, notes, and snippets.

@afreeland
Created July 24, 2017 14:53
Show Gist options
  • Save afreeland/8ed9f75c6abc27f58b0ecbe8031fde82 to your computer and use it in GitHub Desktop.
Save afreeland/8ed9f75c6abc27f58b0ecbe8031fde82 to your computer and use it in GitHub Desktop.
SQL: Remove all duplicates except one
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