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)
 getting latest value

Author  Topic 

gangadhara.ms
Aged Yak Warrior

549 Posts

Posted - 2012-02-14 : 03:15:33
Hi

I have a table which is having datemodified column i need to get only one latest value from the table.



Thanks,
Gangadhara MS
SQL Developer and DBA

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2012-02-14 : 03:31:05
select max(YourDatemodifiedColumn) from table


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2012-02-14 : 03:31:18
select * from table
where datemodified =(select max(datemodified) from table)

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

senthil_nagore
Master Smack Fu Yak Hacker

1007 Posts

Posted - 2012-02-14 : 03:39:24
Select top 1 * from table order by datemodified desc

Senthil Kumar C
------------------------------------------------------
MCITP - Database Administration SQL SERVER 2008
MCTS - Database Development SQL SERVER 2008
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-02-14 : 09:59:11
quote:
Originally posted by senthil_nagore

Select top 1 * from table order by datemodified desc

Senthil Kumar C
------------------------------------------------------
MCITP - Database Administration SQL SERVER 2008
MCTS - Database Development SQL SERVER 2008


what if you've multiple records for latest date? you want only one of them of all?

Select top 1 * from table order by datemodified desc

Select top 1 with ties * from table order by datemodified desc



------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2012-02-14 : 14:00:08
quote:
Originally posted by gangadhara.ms
Thanks,
Gangadhara MS
SQL Developer and DBA



You funny



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-02-14 : 14:05:24
quote:
Originally posted by X002548

quote:
Originally posted by gangadhara.ms
Thanks,
Gangadhara MS
SQL Developer and DBA



You funny



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/





Nice catch

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -