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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how do i limit the number of results returned in a select query?

Status
Not open for further replies.

carpeliam

Programmer
Mar 17, 2000
990
US
quite possibly a simple question, but i can't seem to find the answer.

I'd like to say "give me the first 50 results of query x". MySQL does it like this:
Code:
SELECT * FROM table LIMIT 5,10; #this will retrieve rows 6 through 15
I'm hoping for something that will actually limit the number of rows I ask for, not simply ask for everything and then limit the number of rows I display.

Liam Morley
lmorley@wpi.edu
"light the deep, and bring silence to the world.
light the world, and bring depth to the silence."
 
Liam,

In Oracle, to obtain just the first 50 rows of a query, we use the following code:
Code:
SELECT <expression(s)> FROM <table_name>
WHERE ROWNUM <= 50;

If you wish to read the entire table (for example to find the top 50 rows of an ORDER BY, you would say:
Code:
SELECT <expression(s)>
FROM (SELECT <expressions> FROM <table_name> ORDER BY <expression(s)>)
WHERE ROWNUM <= 50;

Let us know if this resolves your need.,

[santa]Mufasa
(aka Dave of Sandy, Utah, USA @ 19:41 (21Jul04) UTC (aka "GMT" and "Zulu"), 12:41 (21Jul04) Mountain Time)
 
that works, thanks:) <p>Liam Morley<br><A HREF="mailto:"></A><br>&quot;light the deep, and bring silence to the world.<br>light the world, and bring depth to the silence.&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top