Select (and delete) duplicite rows

First get rownumber of the same rows. Then select and delete them. If you want to see both rows, then use inner join (on key_columns) CTE or create #tmp

	duplicitiesfordelete as
		select *, row_number() over(partition by <<KEY COLUMNS,>> order by <<column>> desc) as RN 
		from <<TABLE>>
		where <<filter>>)
	select * from duplicitiesfordelete where RN>1 

Leave a Comment

Napsat komentář

Vaše emailová adresa nebude zveřejněna. Vyžadované informace jsou označeny *