Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Duplicate records

Duplicate records

Scheduled Pinned Locked Moved Database
tutorial
7 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Sophia Rekhi
    wrote on last edited by
    #1

    Hi all, How to delete duplicate Records in a table in SQLSERVER.

    J K 2 Replies Last reply
    0
    • S Sophia Rekhi

      Hi all, How to delete duplicate Records in a table in SQLSERVER.

      J Offline
      J Offline
      jijoaresseriljose
      wrote on last edited by
      #2

      hi, suppose col001 of table1 is the duplicated values.then the query "select col001 from table1 group by col001 having count(col001)>1" will get all the duplicate values so, the below query will delete all the duplicated records. "delete from table1 where col001 in ( select col001 from table1 group by col001 having count(col001)>1)" regards Jijo

      jijo jose

      S 1 Reply Last reply
      0
      • S Sophia Rekhi

        Hi all, How to delete duplicate Records in a table in SQLSERVER.

        K Offline
        K Offline
        Krish KP
        wrote on last edited by
        #3

        Add new column to the table and make it IDENTITY so that each row can be identified Uniquely.

        Regards KP

        O 1 Reply Last reply
        0
        • J jijoaresseriljose

          hi, suppose col001 of table1 is the duplicated values.then the query "select col001 from table1 group by col001 having count(col001)>1" will get all the duplicate values so, the below query will delete all the duplicated records. "delete from table1 where col001 in ( select col001 from table1 group by col001 having count(col001)>1)" regards Jijo

          jijo jose

          S Offline
          S Offline
          Sophia Rekhi
          wrote on last edited by
          #4

          Hi jijo jose, Thanks for your response, but your solution deletes all records which are duplicate.even table does n't contain one value. i want only delete duplicated records other than first value' ex: Sample Table Contains records are sno sname 10 XXX 10 XXX 10 XXX 20 YYY 20 YYY But after deletion of duplicate records i want records in table like this : sno sname 10 XXX 20 YYY

          K J 2 Replies Last reply
          0
          • K Krish KP

            Add new column to the table and make it IDENTITY so that each row can be identified Uniquely.

            Regards KP

            O Offline
            O Offline
            one_stone_zz
            wrote on last edited by
            #5

            You can use the temp table, put the only exist records into the temp table then you can delete the original table's records use the condition with the information of the temp table. onestone

            1 Reply Last reply
            0
            • S Sophia Rekhi

              Hi jijo jose, Thanks for your response, but your solution deletes all records which are duplicate.even table does n't contain one value. i want only delete duplicated records other than first value' ex: Sample Table Contains records are sno sname 10 XXX 10 XXX 10 XXX 20 YYY 20 YYY But after deletion of duplicate records i want records in table like this : sno sname 10 XXX 20 YYY

              K Offline
              K Offline
              Krish KP
              wrote on last edited by
              #6

              in continuation to my earlier solution.... select * from tblA where newcol IN (select min(newcol) from tblA group by sno having count(*) > 1) should give first occurance of the each duplicate row. Note : newcol is the new identity colum

              Regards KP

              1 Reply Last reply
              0
              • S Sophia Rekhi

                Hi jijo jose, Thanks for your response, but your solution deletes all records which are duplicate.even table does n't contain one value. i want only delete duplicated records other than first value' ex: Sample Table Contains records are sno sname 10 XXX 10 XXX 10 XXX 20 YYY 20 YYY But after deletion of duplicate records i want records in table like this : sno sname 10 XXX 20 YYY

                J Offline
                J Offline
                jijoaresseriljose
                wrote on last edited by
                #7

                hi, I thought, you wanted to delete all the dubplicated one including original, Then do this in your query analyser......... 1 st step ---------- alter table table1 add [id] int identity 2nd step ---------- delete from table1 where [id] not in (select min([id]) from table1 group by col001) it will delete all the duplicate records from table1 regards Jijo :rolleyes: -- modified at 9:36 Thursday 29th March, 2007

                jijo jose

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups