Grabbing Most-Recent Records from SQLite

How do I pull a particular record (from an SQLite database) whose date column is the most recent?

I might have done it myself.

var sql as string = "SELECT * FROM ExerciseSessions GROUP BY ExerciseID HAVING MAX(pDateTime) ORDER BY pDateTime DESC"

That seems to be working for me at the moment!

This should work too…

select * from exercisesessions order by pdatetime desc limit 1

[quote=486948:@Brandon Warlick]This should work too…

select * from exercisesessions order by pdatetime desc limit 1

My initial request was incomplete… I need that “group by” in there because I have groups of data, and I need the latest of each particular group.

Thank you!

another way to do this is with sub queries

SELECT * 
FROM ExerciseSessions 
where pDateTime in (select MAX(pDateTime) from ExcerciseSessions) 
GROUP BY ExerciseID