tags:

views:

1571

answers:

4

I would like to construct a query that displays all the results in a table, but is offset by 5 from the start of the table. As far as I can tell, MySQL's LIMIT requires a limit as well as an offset. Is there any way to do this?

A: 

SELECT column FROM table LIMIT 10 OFFSET 10

geeeeeeeeeek
lol? how could this possibly be correct?
knittl
yeah, assuming the 10 of the LIMIT clause is a number in base 1000000000000
Petruza
+2  A: 

As you mentioned it LIMIT is required, so you need to use the biggest limit possible, which is 18446744073709551615 (maximum of unsigned BIGINT)

SELECT * FROM somewhere LIMIT 18446744073709551610 OFFSET 5
Czimi
+5  A: 

From the MySQL Manual on LIMIT:

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;

Greg
Awful! I came here hoping that MySQL made the Limit clause optional, as it is, but also with an offset provided... but no!I've seen this 18446744073709551615 scatter all over the code and I was blaming lazy programmers, but it's a design feature!
Petruza
A: 

Another approach would be to select an autoimcremented column and then filter it using HAVING.


SET @a := 0; 
select @a:=@a + 1 AS counter, table.* FROM table 
HAVING counter > 4

But I would probably stick with the high limit approach.

jishi