Is there an efficient way to do an order by and group by so that you get a specific item from each group (from the order by).
//This is the best way i have come up with.
SELECT D.*
FROM (
SELECT *
FROM devices
ORDER BY time
) AS D
GROUP BY D.location
This worked for me
SELECT *
FROM (SELECT *
FROM col
ORDER BY col DESC,date DESC)a
GROUP BY col
SELECT *
FROM devices
GROUP BY D.location
ORDER BY time --ASC or DESC default is ASC i believe
No need for sub-queries
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