MySQL Forums
Forum List  »  Newbie

SELECT grouping problem with MAX()
Posted by: Lyle Hopkins
Date: January 20, 2008 01:38PM

Hi All,
I've been ripping my hair out trying to get this select to return what I want. Here is what I have so far:-

create table paylist (date int(8), username varchar(12), amount real(12,2))

Some example data:-
INSERT into paylist(date, amount, username) values ('20080101', 10, 'bob'), ('20080102', 20, 'bob'), ('20080103', 5, 'bob'), ('20080102, 0, 'laura')

What I want is to get returned is this:-
20080103, 5, bob
20080102, 0, laura

The real table has lots of different users. Now if I use:-

SELECT MAX( date ) AS m, amount, username
FROM `paylist`
WHERE 1
GROUP BY username
ORDER BY m DESC

I Get:-
20080103, 10, bob
20080102, 0, laura

Seems no matter what I try, I cannot get the amount that corrosponds with the MAX( date ).

Please someone help me.


Thank you.

Options: ReplyQuote


Subject
Written By
Posted
SELECT grouping problem with MAX()
January 20, 2008 01:38PM


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.