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 January 26th, 2013, 05:08 PM
Ceeege Ceeege is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2012
Posts: 3 Ceeege User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 31 m 12 sec
Reputation Power: 0
Effecient Query needed to remove duplicates

Hi folks and thanks for reading

I have a quiz feature on my site which stores a score, username and ip address as the most important columns. I currently have a horrible series of views bringing back the high scores based on the criteria I need which are...

Lowest score first but...only the lowest score for each user.

The complexity lies if the user has changed ip, i.e. keeps the same username but has a different ip

It's easier to give you an example

UserID IPA Score
User 1 IP1 13 |
User 1 IP1 20 | First user but from
User 1 IP2 30 | 3 different IP Addresses
User 1 IP3 10 |

User 2 IP4 20 |
User 2 IP5 22 | Second user from 2 IP Addresses
User 2 IP5 15 |

User 3 IP6 12 |
User 3 IP6 20 | Third user using one IP Address
User 4 IP6 15 | but using 3 Usernames
User 5 IP6 11 |


The highscore query would present you with

User 1 IP3 10
User 5 IP6 11
User 2 IP5 15

The score value is highly unlikely to be duplicated but I guess it is possible. The figures above are simplified to explain my conundrum!

Can anyone suggest an efficient way of removing these duplicates as my table is now over 15,000 records and my Views are creaking!

Many thanks.

Reply With Quote
  #2  
Old January 26th, 2013, 07:13 PM
r937's Avatar
r937 r937 is offline
SQL Consultant
Dev Shed God 43rd Plane (26000 - 26499 posts)
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 26,439 r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level) 
Time spent in forums: 3 Months 1 Week 2 Days 13 h 57 m 19 sec
Reputation Power: 4141
15,000 rows is a small table

why do you feel the need to remove data?
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book

Reply With Quote
  #3  
Old January 26th, 2013, 07:23 PM
Ceeege Ceeege is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2012
Posts: 3 Ceeege User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 31 m 12 sec
Reputation Power: 0
Sorry for not being clear. Not physically deleting the duplicates, just returning the rows I want (either as a direct query from the table or as a view).

My current setup uses several views to narrow the results down ensuring that a "visitor" only has one result returned in the High Score query, even if they have changed IP address or Username.

Hopefully the example is a clear enough indication of the result query I'm trying to obtain.

Reply With Quote
  #4  
Old January 26th, 2013, 07:35 PM
r937's Avatar
r937 r937 is offline
SQL Consultant
Dev Shed God 43rd Plane (26000 - 26499 posts)
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 26,439 r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level) 
Time spent in forums: 3 Months 1 Week 2 Days 13 h 57 m 19 sec
Reputation Power: 4141
Quote:
Originally Posted by Ceeege
... even if they have changed IP address or Username.
i think you're gonna have a real problem implementing this particular requirement

if a user can change both his name and his ip, you're not going to able to tell users apart at all

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMySQL Help > Effecient Query needed to remove duplicates

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