Hi @MassimoPallara,
In addition to row_number(), rank() can also be used.
Please refer to:
declare @test table (
Id varchar(3),SecondIdentifier int,Year int, ItemBoxId varchar(30),BoxId int)
insert into @test values('008',1029 ,2020 ,'1C192F5D', NULL),
('009', 1129, 2020 ,'1C192F5D', NULL)
select * from @test
;with cte as (
select *, rank() over(partition by ItemBoxId order by SecondIdentifier ) rn
from @test)
delete from cte
where rn>1
select * from @test
If you have any question, please feel free to let me know.
If the response is helpful, please click "Accept Answer" and upvote it.
Best Regards
Echo
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.