SQL group and order

Posted by John Lambert on Stack Overflow See other posts from Stack Overflow or by John Lambert
Published on 2010-03-11T21:34:06Z Indexed on 2010/03/11 21:39 UTC
Read the original article Hit count: 464

Filed under:
|

I have multiple users with multiple entries recording times they arrive at destinations

Somehow, with my select query I would like to only show the most recent entries for each unique user name.

Here is the code that doesn't work:

SELECT * FROM $dbTable GROUP BY xNAME ORDER BY xDATETIME DESC

This does the name grouping fine, but as far as showing ONLY their most recent entry, is just shows the first entry it sees in the SQL table.

I guess my question is, is this possible?

Here is my data sample:

john  7:00
chris 7:30
greg 8:00
john 8:15
greg 8:30
chris 9:00

and my desired result should only be

john 8:15
chris 9:00
greg 8:30

© Stack Overflow or respective owner

Related posts about sql

Related posts about grouping