I'm trying to create a select query that returns the most recent record from the table based on date. Basically whichever row's [Date] field is closest to the current date.
Sample Data:
ID Content Date
--------------------------------------------
1 1050 Test Values 2013-11-27 10:46:24.900
2 1051 Test Test 2013-11-27 10:47:43.150
3 1057 Test Testx2 2013-11-27 10:48:22.820
I would like to only return these values
ID Content Date
--------------------------------------------
1 1057 Test Testx2 2013-11-27 10:48:22.820
Thanks!
You could try the following query:
SELECT TOP 1 *
FROM Table
ORDER BY [Date] DESC
Or, if you want your query to work on any DBMS (not just SQL Server), use ANSI SQL:
select * from t order by Date desc limit 1
or
select * from t where Date = (select max(Date) from t)
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