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
How about something like
Select xName, MAX(xDATETIME) AS MaxDateVal
FROM $dbtable
GROUP BY xName
ORDER BY MaxDateVal
SELECT xNAME, MAX(xDATETIME)
FROM $dbTable
GROUP BY xNAME
ORDER BY xDATETIME DESC
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With