473,387 Members | 1,517 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How to remove duplicate rows from a temp table

dbrewerton
115 100+
Hello experts, I'm needing some help trying to remove duplicated records from my table. What I mean by duplicated records is they are complimentary records where I have two numbers and these same two numbers get reversed. I'd like to have only one or the other, not both. Here is what the table looks like:

Expand|Select|Wrap|Line Numbers
  1. num1    Owner1    Start1    End1    Descr1                                    num2    Owner2    Start2    End2    Descr2
  2. 123456    John Doe    0:00:00    3:00:00    Reboot Systems                    234567    John Doe    0:00:00    3:00:00    Install Memory
  3. 123456    John Doe    0:00:00    3:00:00    Reboot Systems                    345678    John Doe    0:00:00    3:00:00    Resolve issue with TCPIP packets
  4. 234567    John Doe    0:00:00    3:00:00    Install Memory                    123456    John Doe    0:00:00    3:00:00    Reboot Systems
  5. 234567    John Doe    0:00:00    3:00:00    Install Memory                    345678    John Doe    0:00:00    3:00:00    Resolve issue with TCPIP packets
  6. 345678    John Doe    0:00:00    3:00:00    Resolve issue with TCPIP packets    123456    John Doe    0:00:00    3:00:00    Reboot Systems
  7. 345678    John Doe    0:00:00    3:00:00    Resolve issue with TCPIP packets    234567    John Doe    0:00:00    3:00:00    Install Memory
  8. 345678    John Doe    0:00:00    3:00:00    Resolve issue with TCPIP packets    456789    John Doe    0:00:00    2:00:00    Reinstall Java Applets
  9. 456789    John Doe    0:00:00    2:00:00    Reinstall Java Applets                    345678    John Doe    0:00:00    3:00:00    Resolve issue with TCPIP packets
  10.  
As you can see, I have a bit of a perdicament here. Sometimes, I can have as few as one record being duplicated. In my case, num1 and num2 with all its information gets duplicated.
Jul 14 '11 #1

✓ answered by Rabbit

You will need to add an identity field if you don't already have one.

Then you can use a subquery to select everything except either the min or the max to delete.

Afterwards you can drop the identity field.

1 2611
Rabbit
12,516 Expert Mod 8TB
You will need to add an identity field if you don't already have one.

Then you can use a subquery to select everything except either the min or the max to delete.

Afterwards you can drop the identity field.
Jul 14 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Damien Cobbs | last post by:
Is there a way to remove duplicate rows from a table that does not have a primary key leaving one copy of the row without comparing each column to each other as suggested by the code example below:...
3
by: Diego Rey | last post by:
Hi everyone. How can I get the unique row from a table which contains multiple rows that have exactly the same values. example: create table test ( c1 as smallint, c2 as smallint, c3 as...
5
by: hharry | last post by:
Hello All, I have an issue with dupliate Contact data. Here it is: I have a Contacts table; CREATE TABLE CONTACTS ( SSN int, fname varchar(40),
3
by: imani_technology_spam | last post by:
We were trying to remove duplicates and came up with two solutions. One solution is similar to the one found in a book called "Advanced Transact-SQL for SQL Server 2000" by Ben-Gan & Moreau. This...
3
by: dan graziano | last post by:
Hi, How do you suggest is the best way to check for duplicate rows in an access table. And once one knows if there are duplicates, to remove all but one. In my access table, there are 5...
1
by: TaeHo Yoo | last post by:
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 those duplicate rows at all? This table doesn't...
5
by: dale.zjc | last post by:
I've got the following table data: 11652 5.99 11652 0.14 12996 5.03 12996 0.12 12996 7.00 And I need to write a query to return only rows 2 and 4, since the remaining rows have duplicate...
7
by: Jon Maz | last post by:
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 Key constraint violation, and in my workaround...
2
by: thithu | last post by:
In Sql Server table , there are some duplicate rows i want to delete the duplicate rows without using Cursors and Temp Table
5
jamesd0142
by: jamesd0142 | last post by:
My manager and I where looking at some complex code to eliminate duplicate records in a database table. then it hit me how its done easily... so i thought i'd share it... In English:...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.