Query to delete one of the duplicate rows

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • muzu1232004
    New Member
    • Aug 2007
    • 16

    Query to delete one of the duplicate rows

    Is there any query which will delete exactly one of the duplicate rows in a table and retain only one ?
  • Saii
    Recognized Expert New Member
    • Apr 2007
    • 145

    #2
    Yes there are different ways to delete duplicate rows. What problem are you facing with your query?

    Comment

    • amitpatel66
      Recognized Expert Top Contributor
      • Mar 2007
      • 2358

      #3
      DELETE FROM <TABLE_NAME> WHERE ROWID NOT IN (SELECT MAX(ROWID) FROM <TABLE_NAME> GROUP BY <COLUMN_NAME> HAVING COUNT(COLUMN_NA ME) >= 1)

      Say you have following data:

      Table emp_det

      EMPID ENAME
      101 A
      101 A
      102 B
      102 B

      Then the below query will delete the duplicate records from emp_det table.

      DELETE FROM emp_det WHERE ROWID NOT IN (SELECT MAX(ROWID) FROM emp_det GROUP BY empid HAVING COUNT(empid) >= 1)

      Comment

      • muzu1232004
        New Member
        • Aug 2007
        • 16

        #4
        Thanks for ur reply.
        i had the same problem.

        Comment

        • hashim
          New Member
          • Sep 2007
          • 1

          #5
          hi
          1-first u have to select the rowid for this rows
          using flowing code:
          select rowid from <table_name> where <condition >
          2- delete from <table_name> where rowid=<choose the rowid from previous query>
          3-commit

          Comment

          Working...