SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Most current record
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

sfjtraps
Yak Posting Veteran

63 Posts

Posted - 01/28/2010 :  14:22:38  Show Profile  Reply with Quote
Hi,

Does anyone know how to select the most current record from a table? What to put in the WHERE clause?

Here is my query

SELECT * FROM Snapshot

wHERE Event = 'liveEventTag'


Please help. I only want the most current record.

Thanks,

sfjtraps

Edited by - sfjtraps on 01/28/2010 14:47:39

vijayisonly
Flowing Fount of Yak Knowledge

USA
1836 Posts

Posted - 01/28/2010 :  14:49:02  Show Profile  Reply with Quote
How do you define "most current record"...
Do you have a datetime field in the table which you can use?

Edited by - vijayisonly on 01/28/2010 14:49:22
Go to Top of Page

sfjtraps
Yak Posting Veteran

63 Posts

Posted - 01/28/2010 :  15:04:25  Show Profile  Reply with Quote
I do have a dateTime field as follows:

2010-01-28 12:53:01.280
Go to Top of Page

vijayisonly
Flowing Fount of Yak Knowledge

USA
1836 Posts

Posted - 01/28/2010 :  15:08:17  Show Profile  Reply with Quote
Then you can do it this way..
select top 1 * from <urtable>
order by <urdatetimefield> desc
Go to Top of Page

raky
Aged Yak Warrior

767 Posts

Posted - 01/29/2010 :  05:42:33  Show Profile  Reply with Quote
try this


SELECT top 1 * FROM Snapshot

wHERE Event = 'liveEventTag'

order by <DateField> desc

Note: This gives the top most record which has Event as
LiveEventTag
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.17 seconds. Powered By: Snitz Forums 2000