Home » RDBMS Server » Server Administration » SQL Command that returns only certain rows
SQL Command that returns only certain rows [message #370757] Tue, 01 February 2000 05:45 Go to next message
Rene Bauer
Messages: 1
Registered: February 2000
Junior Member
Hallo,

I would like to do an select with an order by clause that returns only certain rows like 10-20.
I tried a few things like:
select * from tablename where rownum<=20 SELECT ROWNUM<="10" TABLENAME * MINUS COLUMN FROM COLUMN;<BR BY WHERE ORDER>This does not work because SQL complains about the order by. What else can I do?

Ciao,
Rene
Re: SQL Command that returns only certain rows [message #370760 is a reply to message #370757] Tue, 01 February 2000 13:35 Go to previous messageGo to next message
Thierry Van der Auwera
Messages: 44
Registered: January 2000
Member
Hallo,

You can do this, but in a tricky way.
First, when you use an "ORDER BY" and use the "ROWNUM" in one select,
ex: "SELECT rownum,* FROM tablename ORDER BY column" you will see that the
rownums are no more in Ascending Sequence.
So the solution is that you must see that rows are comming directly in the correct
order. We can do this with a subselect, but here you can not use an order by.
But if you create an index on the column to order by, you can specify a hint, so
oracle will give then in the order of the Index
So the Solution is:

SELECT *
FROM (SELECT /*+ (INDEX_ASC(tab1 index_name_column) */
rownum tabrownum
,tab1.*
FROM tablename tab1)
WHERE tabrownum BETWEEN 10 AND 20
;

You see, it is as easy as that.
Hope this works.

Greetings,

Thierry.
Re: SQL Command that returns only certain rows [message #371608 is a reply to message #370760] Tue, 14 November 2000 09:17 Go to previous messageGo to next message
Vengadesvary Candasamy
Messages: 1
Registered: November 2000
Junior Member
Hi,
I'm trying to construct a SQL that returns only certain rows but I am working on Oracle 8.0.3 and this does not allow the use of 'order by' in any view (in-line or otherwise).
Would sincerely appreciate any help on this.

TIA,
Vengs.
Re: SQL Command that returns only certain rows [message #371703 is a reply to message #370760] Mon, 27 November 2000 15:38 Go to previous message
Paul
Messages: 164
Registered: April 1999
Senior Member
Would you please explain this method of returning certain rows in more detail. I would like to do it, but I am not sure how to create an index or how it will help. Thanks.
Previous Topic: Inserting date format into an Oracle table
Next Topic: Query/Insert in a view
Goto Forum:
  


Current Time: Sat May 04 07:07:54 CDT 2024