SQL sorting?
- Pecos
-
Pecos
- Member since: Dec. 29, 1999
- Offline.
-
- Forum Stats
- Member
- Level 03
- Blank Slate
You know how when you search for something in a search engine, they display the first 20 (or something) results on the first page, and then the second 20 on the second page, and so on..
So let's say I have a bunch of records in a table and I need to only pull the first 20, or maybe next time I gotta pull numbers 20-40.. Anyone know how that would be done?
I know that I can load the whole query into an array/vector-type structure, but I'd rather not use up all that memory if I have 800 records. I'd rather specify the 20-40 in the SELECT statement itself.
Is that possible?
- aladinsane
-
aladinsane
- Member since: Jan. 17, 2000
- Offline.
-
- Forum Stats
- Member
- Level 21
- Blank Slate
At 8/28/01 10:18 AM, UnclePecos wrote: You know how when you search for something in a search engine, they display the first 20 (or something) results on the first page, and then the second 20 on the second page, and so on..
So let's say I have a bunch of records in a table and I need to only pull the first 20, or maybe next time I gotta pull numbers 20-40.. Anyone know how that would be done?
I know that I can load the whole query into an array/vector-type structure, but I'd rather not use up all that memory if I have 800 records. I'd rather specify the 20-40 in the SELECT statement itself.
Is that possible?
Yes:
select stuff from somewhere limit 20 // Gets first 20
select stuff from somewhere limit 19 20 // Gets next 20-40
select stuff from somewhere limit 39 20 // Gets 40-60
and so on.
- Pecos
-
Pecos
- Member since: Dec. 29, 1999
- Offline.
-
- Forum Stats
- Member
- Level 03
- Blank Slate
At 8/28/01 10:35 AM, aladinsane wrote: Yes:
select stuff from somewhere limit 20 // Gets first 20
select stuff from somewhere limit 19 20 // Gets next 20-40
select stuff from somewhere limit 39 20 // Gets 40-60
and so on.
Ah sweet, that's what I was looking for. Thanks!

