Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Return Row With Most Recent Timestamp in a Group by Device

Status
Not open for further replies.

WebsterTrivium

Programmer
Feb 21, 2007
1
US
I'm trying to build a query to return the row with the most recent timestamp for each device in a table. Currently I have this:

Code:
SELECT (Fields)
FROM (Database)
WHERE (Conditions)
GROUP BY deviceID 
HAVING MAX(timestamp);

Which simply returns the first row for each device (Or at least, that's what it looks like). The timestamp is simply an int with the Unix Epoch timestamp. deviceID is a string that stores the name of each device.


Any help is greatly appreciated!
 
Code:
select [i]columns /* not fields */ [/i]
  from [i]daTable /* not database */[/i] as T
 where [i]conditions[/i]
   and timestampcol =
       ( select max(timestampcol)
           from daTable
          where deviceid = T.deviceid )

r937.com | rudy.ca
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top