MySQL Forums
Forum List  »  Newbie

Help with using MAX to find highest value
Posted by: Robert Vrabel
Date: December 01, 2008 06:45AM

I'm trying to write a query to find the records with the highest value based off a ID

To simplify the table lets say it is song_id, user_id, date_completed, score

I'm trying to do something simliar to this to return the highest values for each song where the user_id is set to something.

SELECT `song_stats`.*, MAX(score) as max_score FROM `song_stats` WHERE `user_id` = '1' GROUP BY `song_id

The problem with this query is its not returning the actual record where the score is the highest, it is just placing a max_score field in addition to the first field it finds when it does the group by. So my problem is the date_completed field (and all the other fields not mentioned) is not accurate when I get the returned records.

How can I write something simliar to this, but return the EXACT full record of the highest score for each song?

Options: ReplyQuote


Subject
Written By
Posted
Help with using MAX to find highest value
December 01, 2008 06:45AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.