Create table TempTable
(
ID INT,
FName nvarchar(50),
LName nvarchar(50)
)
GO
INSERT TempTable Values ('1','XYZ','PQR')
INSERT TempTable Values ('1','XYZ','PQR')
INSERT TempTable Values ('1','XYZ','PQR')
INSERT TempTable Values ('2','ABC','DEF')
INSERT TempTable Values ('2','ABC','DEF')
INSERT TempTable Values ('2','ABC','DEF')
GO
SELECT * FROM TempTable
----
Delete T From
(
Select row_number() over(order by ID) as row_number,* From temptable
)T
Where row_number NOT IN
(
Select min(row_number)row_number from (Select row_number() over(Order by ID desc) as row_number, * From
Temptable)T
group by ID
)
-------------------------
Delete T From
(
Select row_number() over(partition by ID order by ID) as row_number,* From Temptable
)T
Where row_number>1
No comments:
Post a Comment