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

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 October 27th, 2003, 12:44 AM
gulshan gulshan is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 9 gulshan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Post Search for duplicate rows

Hy,

Could anyone please help me.
I have a table with thousands of rows. I would like to make a query to retrieve only duplicate rows in the table. The query should return rows having 2 columns id1 and id2. id1 and id2 are from duplicate rows in the table. The row should list id1 and id2 only once. How can I implement this query.

thanks in advance

Last edited by gulshan : October 27th, 2003 at 01:10 AM.

Reply With Quote
  #2  
Old October 27th, 2003, 09:11 AM
dcarva's Avatar
dcarva dcarva is offline
Contributing User
ASP Free Novice (500 - 999 posts)
 
Join Date: Jan 2003
Location: USA
Posts: 633 dcarva User rank is Lance Corporal (50 - 100 Reputation Level)dcarva User rank is Lance Corporal (50 - 100 Reputation Level)dcarva User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 9 h 18 m 20 sec
Reputation Power: 6
SELECT id1, id2, COUNT(id1)
FROM Table1
GROUP BY id1, id2

This will show how many times each row was duplicated.

Reply With Quote
  #3  
Old October 30th, 2003, 07:49 AM
gulshan gulshan is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 9 gulshan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I did what you told me, unfortunately this does not work.

Reply With Quote
  #4  
Old October 30th, 2003, 11:43 AM
sbaxter sbaxter is offline
Moderator: Access, SQL
ASP Free God (5000 - 5499 posts)
 
Join Date: Oct 2003
Posts: 5,126 sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 Days 1 h 2 m 51 sec
Reputation Power: 12
DO you want to bring back all duplicate records, or just know which records have duplicates?

S-

Reply With Quote
  #5  
Old October 30th, 2003, 11:48 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
Code:
SELECT id1, id2
FROM table1
GROUP BY(id1, id2) 
HAVING COUNT(id1) > 1

Reply With Quote
  #6  
Old October 30th, 2003, 10:31 PM
gulshan gulshan is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 9 gulshan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
bring back all duplicate records

Reply With Quote
  #7  
Old October 31st, 2003, 10:22 AM
sbaxter sbaxter is offline
Moderator: Access, SQL
ASP Free God (5000 - 5499 posts)
 
Join Date: Oct 2003
Posts: 5,126 sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 Days 1 h 2 m 51 sec
Reputation Power: 12
What this is using a SELECT Statment the dcarva gave you, I am joining it back to the orginal table to give you a listing of all Duplicate records.

Use this as a template. You will have to specify which fields you want to see and which field make a record duplicate.

In this example I have two fields that make a record duplicate and that I want to see when it is all said and done


SELECT Table2.FieldOne, Table2.FieldTwo
FROM Table2 INNER JOIN [SELECT Table2.FieldOne, Table2.FieldTwo, Count(Table2.FieldOne) AS CountOfFieldOne
FROM Table2
GROUP BY Table2.FieldOne, Table2.FieldTwo
HAVING (((Count(Table2.FieldOne))>1))]. AS PLAY_GROUP
ON ( [PLAY_GROUP].[FieldOne]=[Table2].[FieldOne])
AND ( [PLAY_GROUP].[FieldTwo]=[Table2].[FieldTwo]);

Orginal Data
FieldOne | FieldTwo|
45 | 78
45 | 78
98 | 78
98 | 78
45 | 78

Statement brings back
FieldOne | FieldTwo|
45 | 78
45 | 78
98 | 78
98 | 78

Hope this helps
S-

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseSQL Development > Search for duplicate rows


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