Re: SQL question.

From: Mark Gumbs <mgumbs_at_nospam.hotmail.com>
Date: Mon, 14 Jun 1999 10:16:14 +0100
Message-ID: <3764c607.0_at_145.227.194.253>


Unfortunately, this won't work.
This will take the first 10 rows it finds and do a sort only on those rows. Be careful with rownum, it is only useful in very basic SQL!

Try

select customer_id, name from customer c1 where 10 > (select count(*) from customer c2 where c1.customer_id < c2.customer_id);

This will sort on customer id and return the first 10.

Look at Ken Atkins website and the article http://www.arrowsent.com/oratip/tip38.htm for more details.

Mark

armaghan_at_usa.net wrote in message <7k2bqm$j9u$1_at_nnrp1.deja.com>...
>This trick might help if you want to lookup last 10 rows according to
>some order:
>
>SELECT *
>FROM CUSTOMERS
>WHERE ROWNUM<10
>ORDER BY customer_id DESC (or anything else);
>
>Regards,
>M. Armaghan Saqib (armaghan_at_geocities.com)
>Oracle Link for MS Excel. A free tool to integrate XL with Oracle.
>http://www.geocities.com/WallStreet/Floor/8484/
>
>
>In article <3760B12C.A9D5643B_at_tissat.es>,
> Roberto =?iso-8859-1?Q?P=E9rez?= Lita <rperez_at_tissat.es> wrote:
>
>> Hello,
>>
>> I wonder if there is a way to select, for instance, the last 10 rows
>of
>> a table. I know that i can select the first 10 rows by:
>>
>> SELECT *
>> FROM CUSTOMERS
>> WHERE ROWNUM<10;
>>
>> Thanks in advance.
>> Roberto Pérez Lita.
>
>
>
>Sent via Deja.com http://www.deja.com/
>Share what you know. Learn what you don't.
Received on Mon Jun 14 1999 - 11:16:14 CEST

Original text of this message