Monday 19 May 2014

select or delete only duplicate from table using sql query

WITH QueryTable   AS (
  SELECT RN = ROW_NUMBER() OVER (PARTITION BY salary ORDER BY salary )
         , salary
         , userid
  FROM   emp where salary<>''
)
select * FROM QueryTable   WHERE RN > 1
or
delete  FROM QueryTable    WHERE RN > 1 

No comments:

Post a Comment

Excel Sort values in ascending order using function TEXTJOIN

 Excel ::  Text ::  1,3,5,2,9,5,11 Result :: 1,2,3,5,5,9,11 Formula ::     TEXTJOIN ( ",",1,SORT(MID(SUBSTITUTE( A1 ,","...