6

How can I select all records except first 10 records from MySQL table?

(I know that limit 10,x selects records from the 10th to x-th, but what should I use instead of x to select all remaining records?)

feri baco
  • 615
  • 4
  • 8
  • 15

2 Answers2

7

Use OFFSET. Then you can skip 10 records and select the remaining ones until the end.

Then your query should look like

SELECT field FROM table WHERE (condition) LIMIT 18446744073709551615 OFFSET 10;
Lucia Pasarin
  • 2,268
  • 1
  • 21
  • 37
  • `OFFSET` is not a valid MySQL clause. – Graham Jun 02 '13 at 17:38
  • 1
    `OFFSET` *is* a valid mysql clause. The problem is that it must be after the `LIMIT` clause or it won't work. Check the docs : http://dev.mysql.com/doc/refman/5.0/en/select.html – Tomás Jun 02 '13 at 17:40
  • 1
    @Tomas, yes it's valid as part of a `LIMIT`, but not on its own as the above answer was implying. – Graham Jun 02 '13 at 17:41
  • Edited. 18446744073709551615 is the number that I found is used in the documentation to get records until the last one. – Lucia Pasarin Jun 02 '13 at 17:48
  • 3
    Also, the same query can be done like this `LIMIT 10, 18446744073709551615` – Tomás Jun 02 '13 at 17:51
0

Better get used to LIMIT condition because you can use it also for pagination.

Tomasz Kapłoński
  • 1,320
  • 4
  • 24
  • 49