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)
 Select LAST 10 * ....?

Author  Topic 

cecilius
Starting Member

19 Posts

Posted - 2002-09-15 : 04:10:08
Hi, is there an opposite clause to TOP, like LAST for use with select-statements? Or, is there any way to get this:
select LAST 10 * FROM (SELECT TOP 50 * from ...

Thank you very much and best regards

ceci

BigRetina
Posting Yak Master

144 Posts

Posted - 2002-09-15 : 04:14:38
SELECT TOP 10 Id
FROM Table1
WHERE Id in (SELECT TOP 20 Id
FROM Table1
ORDER BY Quantity DESCENDING)
ORDER BY Quantity ASCENDING

READ THIS http://www.sqlteam.com/item.asp?ItemID=566

Go to Top of Page

martybog
Starting Member

1 Post

Posted - 2004-04-22 : 14:12:49
The SELECT statement example will not do what you expect. Here is what it will do (try it in any database):

1. Executing within the parens, it will order ALL of table1.Id in descending order and then take the TOP 20 Id values from the descending list.

2. It will take the TOP 10 Id values from that resulting list and order them ascending.

What you end up with is the 10 records which are 20 records from the "bottom" of the list ordered by Id.
Go to Top of Page

Lewie
Starting Member

42 Posts

Posted - 2004-04-24 : 02:51:07
SELECT Top 10 FUTO,*
FROM (
Select * from
(Select Top 50 <FieldUsedToOrder> as FUTO,* from <Table> order by <FieldUsedToOrder>) a
order by FUTO DESC) b
ORDER BY FUTO
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2004-04-24 : 08:12:47
the opposite of

SELECT TOP 10 FROM .... ORDER BY A ASC

is

SELECT TOP 10 FROM .... ORDER BY A DESC


- Jeff
Go to Top of Page
   

- Advertisement -