Jump to content

[SOLVED] PHP distinct with multiple rows/columns


idire

Recommended Posts

What I need to do is find the maximum value of a column for each distinct username

 

My previous query where all I was doing was looking for the highest values was:

 

SELECT * FROM `record` WHERE skill = '$skill' ORDER BY xp_gained DESC LIMIT 0 , 10

 

I was trying something like this for only one record per person:

 

SELECT DISTINCT (username), xp_gained, end_lvl, date FROM `record` WHERE skill = '$skill' ORDER BY xp_gained DESC LIMIT 0 , 10

 

This doesnt work, how would I retrieve the highest record for each user (but only 1 per user)

correction it doesnt work

 

it retrieves the results, but doesnt put them in order of highest xp_gained

 

EDIT fixed it again using:

 

SELECT username, max(xp_gained) AS xp_gained, end_level, date FROM record WHERE skill = '$skill' GROUP BY username ORDER BY xp_gained DESC LIMIT 0, 10

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.