[thelist] A Little Query Question

Casey aspnet at thecrookstons.com
Fri Dec 2 16:59:22 CST 2005


How about this:

 SELECT TOP 10 FROM (SELECT TOP 20 field1, field2 FROM table1) ORDER BY 
keyID
 DESC

 The sub query selects the top 20.  Then the top query selects the top 10
 from the sub set, but orders it backwards by the keyID.  The keyID by
 defenition always gets bigger by each row, so you are bound to get the last
 10 of the top 20.  Right?

 But, as always I would be open to better ideas.

 Thanks!

 Casey


> ----- Original Message ----- 
> From: "Casey" <aspnet at thecrookstons.com>
> To: "The List" <thelist at lists.evolt.org>
> Sent: Friday, December 02, 2005 4:48 PM
> Subject: Re: [thelist] A Little Query Question
>
>
>> Ok, good idea, but thinking it through, the sub query selects the top 20,
>> then the main query selects the top 10 from the top 20 -- isn't that the
>> same as selecting the top 10?
>>
>> But - you gave me an idea.  Is there a SELECT BOTTOM 10?  You could 
>> select
>> the TOP 20 in the sub query, then select the BOTTOM 10 from that set. 
>> That
>> would give you rows 11-20, right?
>>
>> Casey
>>
>>> ----- Original Message ----- 
>>> From: "Peter Brunone (EasyListBox.com)" <peter at easylistbox.com>
>>>
>>>
>>> There may be a better way, but how about
>>>
>>> "SELECT
>>> TOP 10 FROM (SELECT TOP 20 field1, field2 FROM table1 WHERE... ORDER BY
>>> field2) ORDER BY field1 "
>>>
>>> ?
>>>
>>>
>>> -----Original Message-----
>>>> From: thelist-bounces at lists.evolt.org On Behalf Of Casey
>>>>
>>>> If you wanted to return the top 15 rows from a table, you could say
>>>> "SELECT
>>>> TOP 10 FROM table WHERE..."
>>>>
>>>> How would you word the query if you wanted rows 11 to 20?
>>>>
>>>> (asp.net with MS SQL)
>>>>
>>>> Thanks Tim!!!
>>>>
>>>> Casey
>>>>
>>>>
>>>
>>
> 




More information about the thelist mailing list