Microsoft SQL Server
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseMicrosoft SQL Server

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old January 11th, 2005, 09:55 PM
joehettinger joehettinger is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 4 joehettinger User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 m 20 sec
Reputation Power: 0
Question distinct column

I have a utility that uploads to a SQL table and gives each record a unique key. The utility checks all the records for a marker to see if it has been uploaded or not. Occasionally it will not mark the record and upload two or three times or more. Since it generates a unique key on upload, how do you run a query that will find and delete all the duplicates and leave on of the original records that were duplicated?

I have about 25 fields in the SQL table, and the "id" is the SQL table key, and the invoice is the key from my original table that I upload from. So if I have invoice numbers 1, 2, 2, 3, 4, 5 you can see that I have to delete one of the records with an invoice of "2." The problem is that I have about 131,000 records and about 30,000 duplicates. How can I fix this?

Thanks,

Joe

Reply With Quote
  #2  
Old January 11th, 2005, 11:53 PM
Memnoch's Avatar
Memnoch Memnoch is offline
Unholy Moderator
ASP Free God 14th Plane (11500 - 11999 posts)
 
Join Date: Oct 2003
Location: In hell, where did you think?
Posts: 11,760 Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 3 Weeks 5 Days 5 h 22 m 16 sec
Reputation Power: 443
Which field contains the duplicated data?

It would be something like this, depending on you data types.
Code:
SELECT DISTINCT FieldName
FROM TableName
GROUP BY FieldName
HAVING COUNT(*) > 1

Reply With Quote
  #3  
Old January 12th, 2005, 05:31 AM
joehettinger joehettinger is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 4 joehettinger User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 m 20 sec
Reputation Power: 0
every field has a dup, except the key id for those dup records. I still need to keep 1 of the dup records, and delete the rest.

Reply With Quote
  #4  
Old January 12th, 2005, 08:43 AM
Memnoch's Avatar
Memnoch Memnoch is offline
Unholy Moderator
ASP Free God 14th Plane (11500 - 11999 posts)
 
Join Date: Oct 2003
Location: In hell, where did you think?
Posts: 11,760 Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 3 Weeks 5 Days 5 h 22 m 16 sec
Reputation Power: 443
try my example and just insert a field name that contains duplicate information.

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseMicrosoft SQL Server > distinct column


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway