how to eliminate duplicate rows?

Ask a Question related to ASP Database, Design and Development.

  1. #1

    Default how to eliminate duplicate rows?

    Hi
    I have one table with two field in sql server 2000.
    Table data looks like this:

    Field1 Field2

    Admin Active
    Admin Passive
    Sales Active
    Sales Passive
    Systems Active
    Systems Active
    Admin Passive
    Sales Passive

    Can any one suggest how to write sql query to eliminate
    duplicates records(duplicate rows) from the table???
    Thanx
    dave

    dave Guest

  2. Similar Questions and Discussions

    1. MySql UPDATE problem with duplicate rows
      Hi, I have a MySql problem I hope someone can help me with. I'm trying to run an update on a linking table, the update is running into a Primary...
    2. How to delete duplicate rows?
      This one must be obvious for most here. I have a 170 million rows table from which I want to eliminate duplicate "would be" keys and leave only...
    3. Eliminate gap between table rows?
      I made my first PHP page that uses includes. http://php.didah.com/main.php But I can't get rid of a gap (about 5 pixels) between the table rows. ...
    4. How to eliminate margin
      On a page I have a table with a single <tr> & <td> containing a flash movie and some graphics. With the flash file, there is a 3-4 pixel white space...
    5. Could anyone help me to remove duplicate rows?
      I have a table that has more than 1 milion rows so practically it is impossible to remove all duplicate rows by hand. Could you help me to remove...
  3. #2

    Default Re: how to eliminate duplicate rows?

    SELECT column1, column2 FROM table GROUP BY column1, column2

    --
    [url]http://www.aspfaq.com/[/url]
    (Reverse address to reply.)




    "dave" <anonymous@discussions.microsoft.com> wrote in message
    news:2251b01c45ca4$c2611230$a001280a@phx.gbl...
    > Hi
    > I have one table with two field in sql server 2000.
    > Table data looks like this:
    >
    > Field1 Field2
    >
    > Admin Active
    > Admin Passive
    > Sales Active
    > Sales Passive
    > Systems Active
    > Systems Active
    > Admin Passive
    > Sales Passive
    >
    > Can any one suggest how to write sql query to eliminate
    > duplicates records(duplicate rows) from the table???
    > Thanx
    > dave
    >

    Aaron [SQL Server MVP] Guest

  4. #3

    Default Re: how to eliminate duplicate rows?

    Thanx Aaron
    Result shows distinct records that I need to keep in the
    table. But how can I delete the rest of them?
    Dave
    >-----Original Message-----
    >SELECT column1, column2 FROM table GROUP BY column1,
    column2
    >
    >--
    >[url]http://www.aspfaq.com/[/url]
    >(Reverse address to reply.)
    >
    >
    >
    >
    >"dave" <anonymous@discussions.microsoft.com> wrote in
    message
    >news:2251b01c45ca4$c2611230$a001280a@phx.gbl...
    >> Hi
    >> I have one table with two field in sql server 2000.
    >> Table data looks like this:
    >>
    >> Field1 Field2
    >>
    >> Admin Active
    >> Admin Passive
    >> Sales Active
    >> Sales Passive
    >> Systems Active
    >> Systems Active
    >> Admin Passive
    >> Sales Passive
    >>
    >> Can any one suggest how to write sql query to eliminate
    >> duplicates records(duplicate rows) from the table???
    >> Thanx
    >> dave
    >>
    >
    >
    >.
    >
    dave Guest

  5. #4

    Default Re: how to eliminate duplicate rows?

    Oh, you actually want to delete them? My first suggestion would be to
    create a second table, insert the results of the GROUP BY, then add a
    primary key. Drop the old table, rename the new one to the old name.

    --
    [url]http://www.aspfaq.com/[/url]
    (Reverse address to reply.)



    "dave" <anonymous@discussions.microsoft.com> wrote in message
    news:21f4401c45ca9$d72e4a20$a301280a@phx.gbl...
    > Thanx Aaron
    > Result shows distinct records that I need to keep in the
    > table. But how can I delete the rest of them?
    > Dave

    Aaron [SQL Server MVP] Guest

  6. #5

    Default Re: how to eliminate duplicate rows?

    any other alternatives?
    cant do it using single sql statment????
    Dave
    >-----Original Message-----
    >Oh, you actually want to delete them? My first
    suggestion would be to
    >create a second table, insert the results of the GROUP
    BY, then add a
    >primary key. Drop the old table, rename the new one to
    the old name.
    >
    >--
    >[url]http://www.aspfaq.com/[/url]
    >(Reverse address to reply.)
    >
    >
    >
    >"dave" <anonymous@discussions.microsoft.com> wrote in
    message
    >news:21f4401c45ca9$d72e4a20$a301280a@phx.gbl...
    >> Thanx Aaron
    >> Result shows distinct records that I need to keep in
    the
    >> table. But how can I delete the rest of them?
    >> Dave
    >
    >
    >.
    >
    dave Guest

  7. #6

    Default Re: how to eliminate duplicate rows?

    No, because you can't tell a DELETE statement to delete this row:

    Admin Passive

    But not this row:

    Admin Passive

    Because it can't tell them apart. This is one of the dangers you face when
    you neglect to choose a primary key.

    Another way to do it would be to add an IDENTITY column to the table, and
    then see [url]http://www.aspfaq.com/2431[/url]

    --
    [url]http://www.aspfaq.com/[/url]
    (Reverse address to reply.)




    "dave" <anonymous@discussions.microsoft.com> wrote in message
    news:225d401c45ccc$05b77750$a001280a@phx.gbl...
    > any other alternatives?
    > cant do it using single sql statment????
    > Dave
    >
    > >-----Original Message-----
    > >Oh, you actually want to delete them? My first
    > suggestion would be to
    > >create a second table, insert the results of the GROUP
    > BY, then add a
    > >primary key. Drop the old table, rename the new one to
    > the old name.
    > >
    > >--
    > >[url]http://www.aspfaq.com/[/url]
    > >(Reverse address to reply.)
    > >
    > >
    > >
    > >"dave" <anonymous@discussions.microsoft.com> wrote in
    > message
    > >news:21f4401c45ca9$d72e4a20$a301280a@phx.gbl...
    > >> Thanx Aaron
    > >> Result shows distinct records that I need to keep in
    > the
    > >> table. But how can I delete the rest of them?
    > >> Dave
    > >
    > >
    > >.
    > >

    Aaron [SQL Server MVP] Guest

  8. #7

    Default Re: how to eliminate duplicate rows?

    On Sun, 27 Jun 2004 21:54:41 -0700, "dave"
    <anonymous@discussions.microsoft.com> wrote:
    >any other alternatives?
    If you have no primary key, how would you identify *which* is the
    duplicate? :)
    >cant do it using single sql statment????
    The best (safest) method is what Aaron suggested. SELECT DISTINCT to
    a new table, drop the old table and rename the new one.

    Naturally, this assumes this table has no interdependencies with any
    other tables, but it would be tough for any other table to use this
    one without a primary key anyway. Your database design may change the
    way you need to accomplish this. In the future, you could use a
    primary key consisting of the two columns in order to ensure no
    duplication exists.

    Jeff
    >>-----Original Message-----
    >>Oh, you actually want to delete them? My first
    >suggestion would be to
    >>create a second table, insert the results of the GROUP
    >BY, then add a
    >>primary key. Drop the old table, rename the new one to
    >the old name.
    >>
    >>--
    >>[url]http://www.aspfaq.com/[/url]
    >>(Reverse address to reply.)
    >>
    >>
    >>
    >>"dave" <anonymous@discussions.microsoft.com> wrote in
    >message
    >>news:21f4401c45ca9$d72e4a20$a301280a@phx.gbl.. .
    >>> Thanx Aaron
    >>> Result shows distinct records that I need to keep in
    >the
    >>> table. But how can I delete the rest of them?
    >>> Dave
    >>
    >>
    >>.
    >>
    Jeff Cochran Guest

  9. #8

    Default Re: how to eliminate duplicate rows?

    Thanx Aaron
    I added auto number primary key and referred that article
    tht you suggested.
    It solved my problem exactly what I was looking for.
    Once again,
    Thanx
    Dave
    >-----Original Message-----
    >No, because you can't tell a DELETE statement to delete
    this row:
    >
    >Admin Passive
    >
    >But not this row:
    >
    >Admin Passive
    >
    >Because it can't tell them apart. This is one of the
    dangers you face when
    >you neglect to choose a primary key.
    >
    >Another way to do it would be to add an IDENTITY column
    to the table, and
    >then see [url]http://www.aspfaq.com/2431[/url]
    >
    >--
    >[url]http://www.aspfaq.com/[/url]
    >(Reverse address to reply.)
    >
    >
    >
    >
    >"dave" <anonymous@discussions.microsoft.com> wrote in
    message
    >news:225d401c45ccc$05b77750$a001280a@phx.gbl...
    >> any other alternatives?
    >> cant do it using single sql statment????
    >> Dave
    >>
    >> >-----Original Message-----
    >> >Oh, you actually want to delete them? My first
    >> suggestion would be to
    >> >create a second table, insert the results of the GROUP
    >> BY, then add a
    >> >primary key. Drop the old table, rename the new one
    to
    >> the old name.
    >> >
    >> >--
    >> >[url]http://www.aspfaq.com/[/url]
    >> >(Reverse address to reply.)
    >> >
    >> >
    >> >
    >> >"dave" <anonymous@discussions.microsoft.com> wrote in
    >> message
    >> >news:21f4401c45ca9$d72e4a20$a301280a@phx.gbl...
    >> >> Thanx Aaron
    >> >> Result shows distinct records that I need to keep in
    >> the
    >> >> table. But how can I delete the rest of them?
    >> >> Dave
    >> >
    >> >
    >> >.
    >> >
    >
    >
    >.
    >
    dave Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139