Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.
Suggest some indentation for readability
Source Link
T N
  • 10.6k
  • 1
  • 12
  • 30

It is possible to do what you want is a single query.

;with cte as(  select [ctrc_num], [Ctrc_name], [docu],[adj], [new], [some_date]  ,ROW_NUMBER() over(partition by [ctrc_num] -- group by [ctrc_num]   order by [new], --0 then 1   [some_date] desc --newest first   ) rn  from #StackOverFlow ) delete cte where rn>1 ; select * from #StackOverFlow 

It is possible to do what you want is a single query.

;with cte as( select [ctrc_num], [Ctrc_name],[docu],[adj],[new], [some_date] ,ROW_NUMBER() over(partition by [ctrc_num] -- group by [ctrc_num] order by [new], --0 then 1 [some_date] desc --newest first ) rn from #StackOverFlow ) delete cte where rn>1 ; select * from #StackOverFlow 

It is possible to do what you want is a single query.

;with cte as(  select [ctrc_num], [Ctrc_name], [docu],[adj], [new], [some_date]  ,ROW_NUMBER() over(partition by [ctrc_num] -- group by [ctrc_num]   order by [new], --0 then 1   [some_date] desc --newest first   ) rn  from #StackOverFlow ) delete cte where rn>1 ; select * from #StackOverFlow 
Source Link
Alex Kudryashev
  • 9.5k
  • 3
  • 31
  • 39

It is possible to do what you want is a single query.

;with cte as( select [ctrc_num], [Ctrc_name],[docu],[adj],[new], [some_date] ,ROW_NUMBER() over(partition by [ctrc_num] -- group by [ctrc_num] order by [new], --0 then 1 [some_date] desc --newest first ) rn from #StackOverFlow ) delete cte where rn>1 ; select * from #StackOverFlow