Welcome to SPN

Register and Join the most happening forum of Sikh community & intellectuals from around the world.

Sign Up Now!

Remove Duplicates?

Discussion in 'Information Technology' started by dan, Jul 28, 2006.

  1. dan

    dan
    Expand Collapse
    Guest

    Hi,

    I have a table similiar to this:

    ColA Col B
    100 Dog
    101 Cat
    101 Horse
    102 ouse


    When there is a duplicate in ColA, I want to delete the entire row of
    one of the duplicates and just keep one. Sometimes there might be three
    or four of these, and I just want one. How can i do this? SQL Statement
    or something else?

    Thank you!
     
  2. Loading...


  3. default105

    default105
    Expand Collapse
    Guest

    Sure you could but why is your table field not set up to not allow dulicates
    in this field

    "dan" wrote:

    > Hi,
    >
    > I have a table similiar to this:
    >
    > ColA Col B
    > 100 Dog
    > 101 Cat
    > 101 Horse
    > 102 ouse
    >
    >
    > When there is a duplicate in ColA, I want to delete the entire row of
    > one of the duplicates and just keep one. Sometimes there might be three
    > or four of these, and I just want one. How can i do this? SQL Statement
    > or something else?
    >
    > Thank you!
    >
    >
     
  4. Pieter Wijnen

    Pieter Wijnen
    Expand Collapse
    Guest

    I've had a zillon of those

    the simlpest way (if you don't rate the remainder)

    Sub KillDups()
    Dim Db As DAO.Database
    Dim Rs AS DAO.Recordset
    Dim LastKey as string ' in the ex

    Set db = Access.CurrentDb
    Set Rs = Db.OpenRecordset("SELECT DUPKEY FROM MYTABLE",DAO.dbOpenDynsaset)
    While Not Rs.EOF
    If Rs.Fields(0).Value = LastKey Then
    Rs.Delete
    Else
    LastKey = Rs.Fields(0).Value
    End If
    Rs.Movenext
    Wend

    Pieter


    "dan" <itzdan262@gmail.com> wrote in message
    news:1152294464.961883.185660@s16g2000cws.googlegroups.com...
    > Hi,
    >
    > I have a table similiar to this:
    >
    > ColA Col B
    > 100 Dog
    > 101 Cat
    > 101 Horse
    > 102 ouse
    >
    >
    > When there is a duplicate in ColA, I want to delete the entire row of
    > one of the duplicates and just keep one. Sometimes there might be three
    > or four of these, and I just want one. How can i do this? SQL Statement
    > or something else?
    >
    > Thank you!
    >
     
  5. Pieter Wijnen

    Pieter Wijnen
    Expand Collapse
    Guest

    I've had a zillon of those

    the simlpest way (if you don't rate the remainder)

    Sub KillDups()
    Dim Db As DAO.Database
    Dim Rs AS DAO.Recordset
    Dim LastKey as string ' in the ex

    Set db = Access.CurrentDb
    Set Rs = Db.OpenRecordset("SELECT DUPKEY FROM MYTABLE",DAO.dbOpenDynsaset)
    While Not Rs.EOF
    If Rs.Fields(0).Value = LastKey Then
    Rs.Delete
    Else
    LastKey = Rs.Fields(0).Value
    End If
    Rs.Movenext
    Wend

    Pieter


    "dan" <itzdan262@gmail.com> wrote in message
    news:1152294464.961883.185660@s16g2000cws.googlegroups.com...
    > Hi,
    >
    > I have a table similiar to this:
    >
    > ColA Col B
    > 100 Dog
    > 101 Cat
    > 101 Horse
    > 102 ouse
    >
    >
    > When there is a duplicate in ColA, I want to delete the entire row of
    > one of the duplicates and just keep one. Sometimes there might be three
    > or four of these, and I just want one. How can i do this? SQL Statement
    > or something else?
    >
    > Thank you!
    >




    --
    ----------------------------------------
    I am using the free version of SPAMfighter for private users.
    It has removed 4182 spam emails to date.
    Paying users do not have this message in their emails.
    Get the free SPAMfighter here: http://www.spamfighter.com/len
     
  6. Angus Comber

    Angus Comber
    Expand Collapse
    Guest

    Is there not an SQL statement which can do this?

    Angus

    "Pieter Wijnen"
    <it.isi.llegal.to.send.unsollicited.mail.wijnen.nospam.please@online.replace
    ..with.norway> wrote in message news:eXdwucioGHA.516@TK2MSFTNGP05.phx.gbl...
    > I've had a zillon of those
    >
    > the simlpest way (if you don't rate the remainder)
    >
    > Sub KillDups()
    > Dim Db As DAO.Database
    > Dim Rs AS DAO.Recordset
    > Dim LastKey as string ' in the ex
    >
    > Set db = Access.CurrentDb
    > Set Rs = Db.OpenRecordset("SELECT DUPKEY FROM

    MYTABLE",DAO.dbOpenDynsaset)
    > While Not Rs.EOF
    > If Rs.Fields(0).Value = LastKey Then
    > Rs.Delete
    > Else
    > LastKey = Rs.Fields(0).Value
    > End If
    > Rs.Movenext
    > Wend
    >
    > Pieter
    >
    >
    > "dan" <itzdan262@gmail.com> wrote in message
    > news:1152294464.961883.185660@s16g2000cws.googlegroups.com...
    > > Hi,
    > >
    > > I have a table similiar to this:
    > >
    > > ColA Col B
    > > 100 Dog
    > > 101 Cat
    > > 101 Horse
    > > 102 ouse
    > >
    > >
    > > When there is a duplicate in ColA, I want to delete the entire row of
    > > one of the duplicates and just keep one. Sometimes there might be three
    > > or four of these, and I just want one. How can i do this? SQL Statement
    > > or something else?
    > >
    > > Thank you!
    > >

    >
    >
     
  7. Pieter Wijnen

    Pieter Wijnen
    Expand Collapse
    Guest

    several ways

    http://support.microsoft.com/default.aspx?scid=kb;en-us;139444

    is one way -> google search: remove duplicates sql
    will also provide other ways

    Pieter


    "Angus Comber" <nospam@gmail.com> wrote in message
    news:e1%23bzbnoGHA.1592@TK2MSFTNGP04.phx.gbl...
    > Is there not an SQL statement which can do this?
    >
    > Angus
    >
    > "Pieter Wijnen"
    > <it.isi.llegal.to.send.unsollicited.mail.wijnen.nospam.please@online.replace
    > .with.norway> wrote in message
    > news:eXdwucioGHA.516@TK2MSFTNGP05.phx.gbl...
    >> I've had a zillon of those
    >>
    >> the simlpest way (if you don't rate the remainder)
    >>
    >> Sub KillDups()
    >> Dim Db As DAO.Database
    >> Dim Rs AS DAO.Recordset
    >> Dim LastKey as string ' in the ex
    >>
    >> Set db = Access.CurrentDb
    >> Set Rs = Db.OpenRecordset("SELECT DUPKEY FROM

    > MYTABLE",DAO.dbOpenDynsaset)
    >> While Not Rs.EOF
    >> If Rs.Fields(0).Value = LastKey Then
    >> Rs.Delete
    >> Else
    >> LastKey = Rs.Fields(0).Value
    >> End If
    >> Rs.Movenext
    >> Wend
    >>
    >> Pieter
    >>
    >>
    >> "dan" <itzdan262@gmail.com> wrote in message
    >> news:1152294464.961883.185660@s16g2000cws.googlegroups.com...
    >> > Hi,
    >> >
    >> > I have a table similiar to this:
    >> >
    >> > ColA Col B
    >> > 100 Dog
    >> > 101 Cat
    >> > 101 Horse
    >> > 102 ouse
    >> >
    >> >
    >> > When there is a duplicate in ColA, I want to delete the entire row of
    >> > one of the duplicates and just keep one. Sometimes there might be three
    >> > or four of these, and I just want one. How can i do this? SQL Statement
    >> > or something else?
    >> >
    >> > Thank you!
    >> >

    >>
    >>

    >
    >
     
  8. Pieter Wijnen

    Pieter Wijnen
    Expand Collapse
    Guest

    several ways

    http://support.microsoft.com/default.aspx?scid=kb;en-us;139444

    is one way -> google search: remove duplicates sql
    will also provide other ways

    Pieter


    "Angus Comber" <nospam@gmail.com> wrote in message
    news:e1%23bzbnoGHA.1592@TK2MSFTNGP04.phx.gbl...
    > Is there not an SQL statement which can do this?
    >
    > Angus
    >
    > "Pieter Wijnen"
    > <it.isi.llegal.to.send.unsollicited.mail.wijnen.nospam.please@online.replace
    > .with.norway> wrote in message
    > news:eXdwucioGHA.516@TK2MSFTNGP05.phx.gbl...
    >> I've had a zillon of those
    >>
    >> the simlpest way (if you don't rate the remainder)
    >>
    >> Sub KillDups()
    >> Dim Db As DAO.Database
    >> Dim Rs AS DAO.Recordset
    >> Dim LastKey as string ' in the ex
    >>
    >> Set db = Access.CurrentDb
    >> Set Rs = Db.OpenRecordset("SELECT DUPKEY FROM

    > MYTABLE",DAO.dbOpenDynsaset)
    >> While Not Rs.EOF
    >> If Rs.Fields(0).Value = LastKey Then
    >> Rs.Delete
    >> Else
    >> LastKey = Rs.Fields(0).Value
    >> End If
    >> Rs.Movenext
    >> Wend
    >>
    >> Pieter
    >>
    >>
    >> "dan" <itzdan262@gmail.com> wrote in message
    >> news:1152294464.961883.185660@s16g2000cws.googlegroups.com...
    >> > Hi,
    >> >
    >> > I have a table similiar to this:
    >> >
    >> > ColA Col B
    >> > 100 Dog
    >> > 101 Cat
    >> > 101 Horse
    >> > 102 ouse
    >> >
    >> >
    >> > When there is a duplicate in ColA, I want to delete the entire row of
    >> > one of the duplicates and just keep one. Sometimes there might be three
    >> > or four of these, and I just want one. How can i do this? SQL Statement
    >> > or something else?
    >> >
    >> > Thank you!
    >> >

    >>
    >>

    >
    >




    --
    ----------------------------------------
    I am using the free version of SPAMfighter for private users.
    It has removed 4182 spam emails to date.
    Paying users do not have this message in their emails.
    Get the free SPAMfighter here: http://www.spamfighter.com/len
     

Share This Page