Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

want to display only 20 rec at a time

Status
Not open for further replies.

unicorn11

Programmer
Jun 10, 2000
392
0
0
IN
I am new to oracle so please bare with me

how do i write a query in sql that will return me only 20 rows from my database that would contain 200 records

thanks for the help
regards ::) Unicorn11
abhishek@tripmedia.com

[red]Nothing is permanent in life except Change[red]
 
Try this:

SELECT *
FROM my_table
WHERE rownum < 21

Good luck...


Terry M. Hoey
th3856@txmail.sbc.com

Ever notice that by the time that you realize that you ran a truncate script on the wrong instance, it is too late to stop it?
 
But this will return all the rows that within to 20 limit of the creteria i set

my sql has to have a certain crietia where it is filering the records and then out of those 200 it it would return about 50 of which i have to show 20

thanks Terry ::) Unicorn11
abhishek@tripmedia.com

[red]Nothing is permanent in life except Change[red]
 
Something like the following should work ...

select <mydata>
from
(
select <fulldataselection>
from <srctable>
order by <sortclause>
) subq
where subq.rownum <=20;

This obviously takes a performance hit on large tables, but anything less than 5,000 records should be quick.

The critical point to note is that rownum is assigned to rows in a select statement PRIOR to the order by clause being applied - caught me out many a time!

Cheers,
Mark.
 
&quot;rownum is assigned to rows in a select statement PRIOR to the order by clause being applied&quot;

:) I didn't know that, thx Mark!
Mike
michael.j.lacey@ntlworld.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top