Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5975501
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:05:38+00:00 2026-05-22T21:05:38+00:00

Please don’t ask me why but there is a lot of duplicate data where

  • 0

Please don’t ask me why but there is a lot of duplicate data where every field is duplicated.

For example

alex, 1
alex, 1
liza, 32
hary, 34

I will need to eliminate from this table one of the alex, 1 rows

I know this algorithm will be very ineffecient, but it does not matter. I will need to remove duplicate data.

What is the best way to do this? Please keep in mind I do not have 2 fields, I actually have about 10 fields to check on.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T21:05:39+00:00Added an answer on May 22, 2026 at 9:05 pm

    Method A. You can get a deduped version of your data using

    SELECT field1, field2, ...
    INTO Deduped
    FROM Source
    GROUP BY field1, field2, ...
    

    for example, for your sample data,

    SELECT name, number
    FROM Source
    GROUP BY name, number
    

    yields

    alex    1
    hary    34
    liza    32
    

    then simply delete the old table, and rename the new one. Of course, there are a number of fancy in-place solutions, but this is the clearest way to do it.

    Method B. An in-place method is to create a primary key and delete duplicates that way. For example, you can

    ALTER TABLE Source ADD sid INT IDENTITY(1,1);
    

    which makes Source look like this

    alex    1   1
    alex    1   2
    liza    32  3
    hary    34  4
    

    then you can use

    DELETE FROM Source
    WHERE  sid NOT IN
      (SELECT MIN(sid)
       FROM  Source
       GROUP BY name, number)
    

    which will give the desired result. Of course, “NOT IN” is not exactly the most efficient, but it will do the job. Alternatively, you can LEFT JOIN the grouped table (maybe stored in a TEMP table), and do the DELETE that way.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please don't mind that there is no insert fnc and that data are hardcoded.
Please don't confuse with the title as it was already asked by someone but
I have mutipule web projects (please don't ask me why with multipule namespaces within
I have a flash element (I know, but please don't) with a settings.xml file.
I have a VB6 application (please don't laugh) which does a lot of drawing
I am new to Python so please don't flame me if I ask something
I have a bunch of php arrays that look like this (please don't ask
I know it will sound strange but please don't mind: In C#, let's say
I have a very strange problem , please don’t ask me why do I
Please don't get caught up in my example, just bear with me for the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.