SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Select LAST 10 * ....?
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

cecilius
Starting Member

19 Posts

Posted - 09/15/2002 :  04:10:08  Show Profile  Reply with Quote
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

Jordan
144 Posts

Posted - 09/15/2002 :  04:14:38  Show Profile  Reply with Quote
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

USA
1 Posts

Posted - 04/22/2004 :  14:12:49  Show Profile  Reply with Quote
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

Australia
42 Posts

Posted - 04/24/2004 :  02:51:07  Show Profile  Reply with Quote
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

USA
7423 Posts

Posted - 04/24/2004 :  08:12:47  Show Profile  Visit jsmith8858's Homepage  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000