You can use Common Table Expression combined with ROW_NUMBER()
like this (This is the best way to delete duplicates):
WITH CTE AS(
SELECT t.name,t.salary
ROW_NUMBER() OVER(PARTITION BY t.name,t.salary ORDER BY (SELECT 1)) as rn
FROM YourTable t
)
DELETE FROM CTE WHERE RN > 1
ROW_NUMBER()
will assign each group randomly ranking, only one will get the rank 1
, and every thing else will be deleted.
EDIT: I can suggest something else with out the use of ROW_NUMBER()
:
SELECT distinct t.name,t.salart
INTO TEMP_FOR_UPDATE
FROM YourTable t;
TRUNCATE TABLE YourTable ;
INSERT INTO YourTable
SELECT * FROM TEMP_FOR_UPDATE;
DROP TEMP_FOR_UPDATE;
This will basically create a temp table containing distincted values from your table, truncate your table and re insert the distincted values into your table.