Querying Last Entries group by DeviceId
Posted
by TTCG
on Stack Overflow
See other posts from Stack Overflow
or by TTCG
Published on 2010-05-06T10:17:36Z
Indexed on
2010/05/06
10:18 UTC
Read the original article
Hit count: 268
I have the database table logs as the following:
I would like to extract the last entry of device, pollDate, status. For eg.
deviceId, pollDate, status
1, 2010-95-06 10:53:28, 1
3, 2010-95-06 10:26:28, 1
I tried to run the following query but the distinct only selects the first records, not the latest
SELECT DISTINCT deviceId, pollDate, status
FROM logs
GROUP By deviceId
ORDER BY pollDate DESC
So, could you please help me to extract the latest entries from the table? Thanks.
© Stack Overflow or respective owner