SQL Server - get latest date record - Asked By Fionyy vb on 17-Aug-08 08:34 AM

I have a log table.

I want to get record of latest date. Meaning if 1-May-2008 13:32:22 and 1-May-2008 2:22:21, it will retrieve 1-May-2008 13:32:22 as a result.

how the statement should be?

thaanks in advanced.

Use Select MAX(columnname) - Peter Bromberg replied to Fionyy vb on 17-Aug-08 09:56 AM

Whatever your datetime columnname is.

reply - Binny ch replied to Fionyy vb on 17-Aug-08 11:48 AM

hi,

Let me know the coloumn name as to where your sotring the datwTime..


Example the coloumn name is  Date_time then  use this in your Query will be

  max(Date_time)

OR Use something like this:

SELECT     TOP 1 *  FROM  MyTable  ORDER BY DateField DESC


reply - Binny ch replied to Fionyy vb on 17-Aug-08 11:50 AM

Here is another way to do it:

select * from MyTable where timestampfield = (select max(timestampfield) from MyTable)

Try this - ram kumar replied to Fionyy vb on 17-Aug-08 12:17 PM

Hi

select * from tablename where columnName = max(columnName )

use this query - pravin kumar S replied to Fionyy vb on 18-Aug-08 12:28 AM

useing this query you get the latest date for record

select  date  from Table where timestampfield = (select max(timestampfield) from Table)

Use this - Atul Shinde replied to Fionyy vb on 18-Aug-08 12:53 AM
SELECT TOP 1 *  FROM  MyTable  ORDER BY DateField DESC
check this... - Santhosh N replied to Fionyy vb on 18-Aug-08 01:35 AM

For this you can use

1) TOP

2) ORDER BY

3) DESC

in combination to achieve this...

ex:

SELECT TOP 1 <column names> FROM LogTable ORDER BY logDate DESC

get latest date record - Shailendrasinh Parmar replied to Fionyy vb on 18-Aug-08 01:40 AM
As Mr. Peter said use MAX function in query to get the latest date record.

select * from Employee where date = (select max(date) from table)

Hope this helps.

ramkumar lakshminarayanan replied to Binny ch on 18-Aug-10 05:48 AM
Thanks a lot
I tried the following example in the following link I have post in detail how we can use it --http://www.rajaramsystems.com/2010/08/18/max-date-in-sql-server/%