PDA

View Full Version : selecting rows 10-20


crazygamer
11-15-2005, 07:27 AM
Is there a way to select a certain group of 10 rows? Say, I want to have multiple pages for a huge result. I want 10 rows on each page. How would I go about getting rows 11-20 on page 2?

Thanks.

maghiel
11-15-2005, 10:43 AM
SELECT foo FROM `bar` LIMIT 10, 20

hyperbole
11-15-2005, 05:00 PM
What you want is SELECT * FROM table LIMIT 9,10
The first number tells SQL the offset (from 0), the second tells the number of rows to SELECT.

maghiel: Your SELECT statement would get rows 11 through 31.



.

crazygamer
11-15-2005, 05:02 PM
Yeah, that doesn't work...

I'm using MS SQL (I figured syntax would be the same). I tried this:

SELECT * FROM Deal LIMIT 3, 3
but no success

crazygamer
11-15-2005, 05:11 PM
I seem to have found a solution... I never thought of adding "ms sql" when doing my google searches.


SELECT * FROM
(SELECT TOP 3 * FROM
(SELECT TOP 6 * FROM table ORDER BY foo ASC) AS newtbl
ORDER BY foo DESC) newtbl2
ORDER BY foo

maghiel
11-16-2005, 11:23 AM
What you want is SELECT * FROM table LIMIT 9,10
The first number tells SQL the offset (from 0), the second tells the number of rows to SELECT.

maghiel: Your SELECT statement would get rows 11 through 31.



.
sorry, it was quite early ;)