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

  • Home
  • SEARCH
  • 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 8321145
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T22:54:58+00:00 2026-06-08T22:54:58+00:00

Please suppose that I have a table with a certain, unspecified number of columns.

  • 0

Please suppose that I have a table with a certain, unspecified number of columns.

I would like to delete the rows entirely duplicated, this means the rows which have all the columns matching in equality, leaving out the duplicated and keeping only 1 row.

How could I achieve this?

Example: SQL Server 2005, table with 5 columns FIELD1, FIELD2, FIELD3, FIELD4, FIELD5:

5   3   2   A   J
3   5   2   A   J
5   3   2   A   J
5   3   2   A   J
8   B   8   A   K

The first row, the third row and the fourth row are duplicates, so you have to leave in the table only one of them.

  • 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-06-08T22:55:00+00:00Added an answer on June 8, 2026 at 10:55 pm

    You might employ row_number() to assign numbers to duplicates and delete where rn is greater than one (single occurrance or first duplicate).

    A small test, since Sql Fiddle is not available ATM:

    declare @t table (FIELD1 varchar(10), FIELD2 varchar(10), FIELD3 varchar(10), FIELD4 varchar(10), FIELD5 varchar(10))
    
    insert into @t values ('5', '3', '2', 'A', 'J')
    insert into @t values ('3', '5', '2', 'A', 'J')
    insert into @t values ('5', '3', '2', 'A', 'J')
    insert into @t values ('5', '3', '2', 'A', 'J')
    insert into @t values ('8', 'B', '8', 'A', 'K')
    
    ; with g as (
      select *,
             row_number() over (partition by field1, field2, field3, field4, field5 
                                order by (select null)) rn
        from @t
    )
    delete g
    where rn > 1
    
    select *
    from @t
    

    The downside is that you have to specify all columns. If you want to aviod this, and your table does not have foreign keys and is not referenced by any you might insert DISTINCT data into temporary table, TRUNCATE original and reinsert from temporary table.

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

Sidebar

Related Questions

Suppose we have a table with UserID ,Calendar date and taskName as columns. Please
Suppose that I have a table Attendances (id(integer), login_date(date), login_time(time),logout_time (time)). Now I have
Suppose, I have a table like this- Code | something ------------------ C01 abc C02
Suppose I have a table with columns id, name, phone_type, phone_no and I have
Suppose I have a table view, and I want to implement something like this:
Please suppose that in SQL Server 2005, if you launch the following query: SELECT
Suppose I have database table TABLE1 and there is Column COLUMN1 . The variable
Suppose I have a description column that contains Column Description ------------------ I live in
Suppose I have this table [Table1] Name Mark ------- ------ ABC 10 DEF 10
i am new in sql and i want that , i have a table

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.