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 2000 Forums
 SQL Server Development (2000)
 how to get last three rows using datetime field

Author  Topic 

reddymade
Posting Yak Master

165 Posts

Posted - 2005-11-18 : 15:29:32
Can you please tell me.
I want to get the last three rows which were modified. using the modified_dt field. which has datetime datatype

select * from mytable where modified_dt = ;Thank you very much for the info.

ehorn
Master Smack Fu Yak Hacker

1632 Posts

Posted - 2005-11-18 : 15:32:51
Have a look at the following keywords in BOL:

TOP
ORDER BY
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-11-19 : 00:18:21
select Top 3 columns from mytable where modified_dt = yourDate order by modified_dt DESC

Madhivanan

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

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2005-11-19 : 08:14:14
quote:
Originally posted by minivan

select Top 3 <columnList> from mytable where modified_dt = yourDate order by modified_dt DESC

Minivan

planning to accord is according to plan




Be One with the Optimizer
TG
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-11-19 : 08:20:40
Thats cool

Madhivanan

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

Kristen
Test

22859 Posts

Posted - 2005-11-20 : 02:31:35
If you want to then arrange them in ascending order you could do this - inner loop selects the last 3, outer loop rearranges the order

SELECT *
FROM
(
select Top 3 *
from mytable
ORDER BY modified_dt DESC
) X
ORDER BY modified_dt ASC

Kristen
Go to Top of Page
   

- Advertisement -