Ways to Find and Deleting Dupliacte records IN SQL SERVER ?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • deveshakgec
    New Member
    • Nov 2013
    • 5

    Ways to Find and Deleting Dupliacte records IN SQL SERVER ?

    Ways to Find and Deleting Dupliacte records IN SQL SERVER
    I have solution here...

    Consider table emp
    Column: ID,C1,C2


    1) WE ARE CONSIDER IF ID AS IDENTITY COLUMN
    Code:
    DELETE FROM EMP WHERE ID NOT IN (SELECT MAX(ID) FROM EMP GROUP BY C1 ,C2)

    2) USING ROW_NUMBER()



    Consider table emp
    Column: ID,name

    Code:
    DELETE EMP_T FROM (SELECT ROW_NUMBER() OVER PARTATION BY (ID,NAME) ORDER BY ID) AS ROWID FROM EMP) EMP_T
    WHERE EMP_T.ROWID >1

    3)USING CTE



    Code:
    WITH CTE AS {
    
    SELECT ID,NAME , ROW_NUMBER() OVER (PARTATION BY ID,NAME )AS RANK FROM EMP)
    }
    DELTE FROM CTE WHERE RANK>1
    Last edited by Rabbit; Nov 13 '13, 04:46 PM. Reason: Please use [CODE] and [/CODE] tags when posting code or formatted data.
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    Please use code tags when posting code or formatted data.

    Please read our FAQ on the rules to follow when posting on this forum.

    What is your question? You seem to have answered yourself.

    Comment

    • ck9663
      Recognized Expert Specialist
      • Jun 2007
      • 2878

      #3
      I think he posted this (and the other posts) as articles.

      ~~ CK

      Comment

      • deveshakgec
        New Member
        • Nov 2013
        • 5

        #4
        Hello,

        I will take care from next time.

        Comment

        Working...