Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Most current record

Author  Topic 

sfjtraps
Yak Posting Veteran

65 Posts

Posted - 2010-01-28 : 14:22:38
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

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2010-01-28 : 14:49:02
How do you define "most current record"...
Do you have a datetime field in the table which you can use?
Go to Top of Page

sfjtraps
Yak Posting Veteran

65 Posts

Posted - 2010-01-28 : 15:04:25
I do have a dateTime field as follows:

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

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2010-01-28 : 15:08:17
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 - 2010-01-29 : 05:42:33
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
   

- Advertisement -