[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.sqlserver.programming

How to return most recent row?

JustDoIt

3/29/2007 2:22:00 AM

One of the columns in my table is a date/time. What is the query to return
the most recent record? I would think this should be simple but my SQL
skills are pretty rusty. Using SQL Server 2000 but would prefer to keep it
as generic SQL as possible

Thanks.


2 Answers

Tom Cooper

3/29/2007 2:29:00 AM

0

select <column list>
from <tablename>
where <datetime column> = (select max(<datetime column>) from <tablename>);

Tom

"Jen" <none@nowhere.com> wrote in message
news:uof81iacHHA.3616@TK2MSFTNGP05.phx.gbl...
> One of the columns in my table is a date/time. What is the query to
> return the most recent record? I would think this should be simple but my
> SQL skills are pretty rusty. Using SQL Server 2000 but would prefer to
> keep it as generic SQL as possible
>
> Thanks.
>


Aaron [SQL Server MVP]

3/29/2007 3:33:00 AM

0

SELECT TOP 1 <column_list>
FROM <table_name>
ORDER BY <date_time_column_name> DESC;

--
Aaron Bertrand
SQL Server MVP
http://www.sq...
http://www.aspfa...



"Jen" <none@nowhere.com> wrote in message
news:uof81iacHHA.3616@TK2MSFTNGP05.phx.gbl...
> One of the columns in my table is a date/time. What is the query to
> return the most recent record? I would think this should be simple but my
> SQL skills are pretty rusty. Using SQL Server 2000 but would prefer to
> keep it as generic SQL as possible
>
> Thanks.
>