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

How to highlight selected text in notepad++

  –> To highlight a block of code in Notepad++, please do the following steps step-1  :- Select the required text. step-2  :- Right click...