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. deleting duplicate rows

deleting duplicate rows

Scheduled Pinned Locked Moved Database
database
6 Posts 2 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.
  • O Offline
    O Offline
    okkishore
    wrote on last edited by
    #1

    how can we delete duplicate rows when we are not using constraints usings query only kishore kumar.B

    K 1 Reply Last reply
    0
    • O okkishore

      how can we delete duplicate rows when we are not using constraints usings query only kishore kumar.B

      K Offline
      K Offline
      kubben
      wrote on last edited by
      #2

      Select all the field you are concerned about and do a group by with a having Something like this: Select col1, col2, col3, col4, col5 from yourTable group by col1, col2, col3, col4, col5 having count(*) > 1 Hope that helps. Ben

      O 1 Reply Last reply
      0
      • K kubben

        Select all the field you are concerned about and do a group by with a having Something like this: Select col1, col2, col3, col4, col5 from yourTable group by col1, col2, col3, col4, col5 having count(*) > 1 Hope that helps. Ben

        O Offline
        O Offline
        okkishore
        wrote on last edited by
        #3

        it can't deleting it only selecting. for select we are also select select DISTINCT * from tablename i need for deleting not for selecting kishore

        K 1 Reply Last reply
        0
        • O okkishore

          it can't deleting it only selecting. for select we are also select select DISTINCT * from tablename i need for deleting not for selecting kishore

          K Offline
          K Offline
          kubben
          wrote on last edited by
          #4

          The query I gave you is to identify the duplicates. Once you have the duplicates there are several things you can do to delete them. If you already know how to identify the duplicates then you should be able to delete them. You can not use a distinct since that removes the duplicates. Do you have any id column or key column to uniquely identify each column? Ben

          O 1 Reply Last reply
          0
          • K kubben

            The query I gave you is to identify the duplicates. Once you have the duplicates there are several things you can do to delete them. If you already know how to identify the duplicates then you should be able to delete them. You can not use a distinct since that removes the duplicates. Do you have any id column or key column to uniquely identify each column? Ben

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

            any one i what that means the table that can have duplicate rows or particular rows.i already mension i can't give any constraints .

            K 1 Reply Last reply
            0
            • O okkishore

              any one i what that means the table that can have duplicate rows or particular rows.i already mension i can't give any constraints .

              K Offline
              K Offline
              kubben
              wrote on last edited by
              #6

              Ok well, if you don't have any unique key you should create one. Add a new column that is an identity. Then if you really don't which record you keep you can do a delete statement like this: delete from yourTable yt join (Select max(id),col1, col2, col3, col4, col5 from yourTable group by col1, col2, col3, col4, col5 having count(*) > 1) temp on yt.id = temp.id Ben

              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