views:

24

answers:

1

I'm having problem with GROUP BY. It returns the first entry it could find, but I would like it to return the last entry. Is that possible?

Here is my query (prepared query):

SELECT stamp_user, stamp_date, stamp_type
FROM rws_stamps
WHERE stamp_date >= ?
GROUP BY stamp_user
ORDER BY stamp_date DESC

My table looks like this:

alt text

What I want it to return is row 7 and 3, but i get 1 and 2.

+1  A: 

Try:

SELECT stamp_user, max(stamp_date), stamp_type
FROM rws_stamps
WHERE stamp_date >= ?
GROUP BY stamp_user, stamp_type
Kangkan
I used this together with some PHP to get it to work.
Marwelln