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
  1. Home
  2. Database & SysAdmin
  3. Database
  4. delete duplicate rows

delete duplicate rows

Scheduled Pinned Locked Moved Database
databasequestion
7 Posts 5 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
    ss444444
    wrote on last edited by
    #1

    Can any one tell the query to delete only duplicate rows from any table ?

    A N B N 4 Replies Last reply
    0
    • S ss444444

      Can any one tell the query to delete only duplicate rows from any table ?

      A Offline
      A Offline
      Ashfield
      wrote on last edited by
      #2

      You need to do it in steps:

      Select * into #table from mytable where 1 = 2

      insert into #table select distinct * from mytable

      truncate table mytable

      insert into mytable select * from #table

      Bob Ashfield Consultants Ltd

      1 Reply Last reply
      0
      • S ss444444

        Can any one tell the query to delete only duplicate rows from any table ?

        N Offline
        N Offline
        Niraj_Silver
        wrote on last edited by
        #3

        Example Table : Cl1 Cl2 ID SecndClmnNAme Delete From Tab Where ID NOt In Select Distinct ID From Tab)

        A 1 Reply Last reply
        0
        • S ss444444

          Can any one tell the query to delete only duplicate rows from any table ?

          B Offline
          B Offline
          Blue_Boy
          wrote on last edited by
          #4

          delete from tablename where id not in (select distinct id from tablename )


          I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post.

          A 1 Reply Last reply
          0
          • B Blue_Boy

            delete from tablename where id not in (select distinct id from tablename )


            I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post.

            A Offline
            A Offline
            Ashfield
            wrote on last edited by
            #5

            Are you sure this works? Surely, if there are duplicate rows there are duplicate ids? I mean, if you have this id name 1 bob 2 fred 1 bob your query will not delete anything as all ids occur in the distinct. Or have I missed something?

            Bob Ashfield Consultants Ltd

            1 Reply Last reply
            0
            • N Niraj_Silver

              Example Table : Cl1 Cl2 ID SecndClmnNAme Delete From Tab Where ID NOt In Select Distinct ID From Tab)

              A Offline
              A Offline
              Ashfield
              wrote on last edited by
              #6

              Are you sure this works? Surely, if there are duplicate rows there are duplicate ids? I mean, if you have this id name 1 bob 2 fred 1 bob your query will not delete anything as all ids occur in the distinct. Or have I missed something?

              Bob Ashfield Consultants Ltd

              1 Reply Last reply
              0
              • S ss444444

                Can any one tell the query to delete only duplicate rows from any table ?

                N Offline
                N Offline
                nelsonpaixao
                wrote on last edited by
                #7

                you are not suppose to have that problem you know?! my advice for you is to start all from the beginning!!! Question yourself why you need that? can´t you achieve what you want to do without creating duplicate rows? can you see that you are creating unnecessary procedures! trying to help you there:rose:

                nelsonpaixao@yahoo.com.br trying to help & get help

                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