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

How to specific number of records to retreive in a query?

Status
Not open for further replies.

dmkFoto

Programmer
Jul 9, 2007
20
US
My item file contains too many records to display. I want to limit the display to only 20 records at a time.

In the Select statement, how do I specify the the first 20 records, 2nd 20, etc.?

Thanks.

Alex
 
Surprisingly enough, you need to use LIMIT.
Code:
SELECT *From table where x=y LIMIT 20;

This will return only 20 records.



----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Oop! Spoke too soon.

If, to get 20 records, starting with the first record is . .

Limit 0, 20

Is the second 20 records . . .

Limit 21, 20

or:

Limit 20, 20

I am confuse with the zero base.

Alex
 
How many total records does your table have? If you need to see all of them but filter them, you could just export the results to a spreadsheet and filter there. Of course, that only works if your resultset is smaller than 65,536 records since that's Excel's limit. I'm trying to understand why you only want to see 20 records at one time
 
The First number indicates In what row of the results you want to start. the second is how many rows you want to return starting from the first number, so:

0,10 would return the first ten rows, 0-9
5,5 would return five rows starting from row number 5, which would be rows 6,7,8,9,10

20,20 would return twenty records starting from row 20. Returning rows 21.22.23.24....30.


----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 

the first parameter is the number of rows to skip over

the first twenty is LIMIT 0,20 because you skip over 0 rows

the second twenty is LIMIT 20,20 -- since you skip over 20 rows, you are starting from row 21

r937.com | rudy.ca
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top