MySQL Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsDatabasesMySQL Help

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 Dev Shed Forums Sponsor:
  #1  
Old December 5th, 2012, 08:01 AM
stalnley112233 stalnley112233 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 3 stalnley112233 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 27 m 45 sec
Reputation Power: 0
Finding rows with duplicate data?

Any help or direction would be appreciated not sure exactly where to start.

I have one table 5 columns, ID is the primary key and the 4 additional columns are text fields.
e.g.
ID A B C D
1 1 2 1 2
2 1 2 1 2
3 1 2 1 2
4 1 2 1 2
5 4 3 2 1
6 4 3 2 1
7 3 2 1 1

When columns A, B, C, D all match for four or more rows (ID’s) I would like to return those ID’s

In the above example I would like the query to return ID = 1,2,3,4. As those ID's all have A=1, B=2, C=1 and D-2.
Note Columns A, B, C, D are text fields and there will be multiple IDs that need to be returned with different values in columns A, B, C, D, I dont want to search for A=x, B=y etc.

Thank you in advance for your assistance.

Reply With Quote
  #2  
Old December 5th, 2012, 08:14 AM
swampBoogie swampBoogie is offline
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jan 2003
Location: Paris Uppland
Posts: 2,349 swampBoogie User rank is Major (30000 - 40000 Reputation Level)swampBoogie User rank is Major (30000 - 40000 Reputation Level)swampBoogie User rank is Major (30000 - 40000 Reputation Level)swampBoogie User rank is Major (30000 - 40000 Reputation Level)swampBoogie User rank is Major (30000 - 40000 Reputation Level)swampBoogie User rank is Major (30000 - 40000 Reputation Level)swampBoogie User rank is Major (30000 - 40000 Reputation Level)swampBoogie User rank is Major (30000 - 40000 Reputation Level)swampBoogie User rank is Major (30000 - 40000 Reputation Level)swampBoogie User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 4 Days 7 h 10 m 28 sec
Reputation Power: 390
Code:
select id 
  from t
 where (c1,c2,c3,c4) in
      (select c1,c2,c3,c4
         from t
        group
           by c1,c2,c3,c4
       having count(*) >= 4)

Reply With Quote
  #3  
Old December 5th, 2012, 08:49 AM
stalnley112233 stalnley112233 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 3 stalnley112233 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 27 m 45 sec
Reputation Power: 0
Got it thank you.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMySQL Help > Finding rows with duplicate data?

Developer Shed Advertisers and Affiliates



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 | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap