tags:

views:

98

answers:

6

Is there a way in MySQL to have the first 10 result from a SELECT query skipped? I'd like it to work something like LIMIT.

A: 

LIMIT allow you to skip any number of rows. It has two parameters, and first of them - how many rows to skip

Col. Shrapnel
+7  A: 

From the manual:

To retrieve all rows from a certain offset up to the end of the result set, you can use some large number for the second parameter. This statement retrieves all rows from the 96th row to the last:

SELECT * FROM tbl LIMIT 95,18446744073709551615;

Obviously, you should replace 95 by 10. The large number they use is 2^64 - 1, by the way.

Thomas
What if I have more than 18446744073709551615 records? :-)
ceejayoz
at 1byte each, you could be waiting a while :P ~ 18pB...
Kurru
@ceejayoz: Then you have a machine from at least 50 years in the future and you probably wouldn't be programming MySQL queries :P
Thomas
+9  A: 

Use LIMIT with two parameters. For example, to return results 11-60 (where result 1 is the first row), use:

SELECT * FROM foo LIMIT 10, 50

For a solution to return all results, see Thomas' answer.

Dominic Rodger
+6  A: 

There is an OFFSET as well that should do the trick:

SELECT column FROM table
LIMIT 10 OFFSET 10
jamesaharvey
+1  A: 

OFFSET is what you are looking for.

SELECT * From table limit 10 offset 10

Ian
A: 

Just like Thomas said.

SELECT * FROM table LIMIT 10, 20;

Will select results between 10th and 20th row.

realshadow
not really, it will select rows 10 to 30. first is the offset, second is the number of rows to select
knittl