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)
 selecting max N rows

Author  Topic 

gobotsoup
Starting Member

6 Posts

Posted - 2007-07-20 : 13:27:31
hello here is my problem:

I need to first order a bunch of rows by date, then select the top ten of those rows. SOrry this should be easy, but I am pretty new at this.

dinakar
Master Smack Fu Yak Hacker

2507 Posts

Posted - 2007-07-20 : 13:31:02
(1) Questions like these have to include some sample data and expected output.
(2) similar question has been answered. Check out the sticky post in the "New to SQL Server" section.

Dinakar Nethi
************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/
Go to Top of Page

rudesyle
Posting Yak Master

110 Posts

Posted - 2007-07-20 : 13:32:29


select top 10 recs
from table
order by date
Go to Top of Page

gobotsoup
Starting Member

6 Posts

Posted - 2007-07-20 : 13:37:49
quote:
Originally posted by rudesyle



select top 10 recs
from table
order by date



Doesn't the order by happen after the selection is made? I need all of the dates in the table ordered by date and then get the top ten.

dinakar: I couldnt find the article you are talking about.
Go to Top of Page

dinakar
Master Smack Fu Yak Hacker

2507 Posts

Posted - 2007-07-20 : 13:40:53
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=55210

Dinakar Nethi
************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/
Go to Top of Page

jezemine
Master Smack Fu Yak Hacker

2886 Posts

Posted - 2007-07-20 : 14:11:15
order happens first, then the top N rows are cut off, so rudesyle's code is what you want.


elsasoft.org
Go to Top of Page

gobotsoup
Starting Member

6 Posts

Posted - 2007-07-20 : 14:22:05
Thanks a lot!
Go to Top of Page
   

- Advertisement -