7 Answers
7

First of all, clearly there is no order in the query provided. Assuming the order is ascending on some field this would be the query @DannyFox meant:

SELECT * FROM T
ORDER BY val
LIMIT 0 , 30

Now imagine we have simplified data, such as a, b, c, d, e and that we want only 3 rows instead of 30:

SELECT * FROM T
ORDER BY val
LIMIT 3

If this returns: a, b, c, d, e in each row, then he would expect to get c, d, e in that order. The query everyone is providing:

SELECT * FROM T
ORDER BY val desc
LIMIT 3

Would return e, d, c. The problem with this is that it's actually changing the original order, and the OP say he didn't want to change the order. So technically, the query that would result in c, d, e is:

select * from (
select * from t
order by val desc
limit 3
) s
order by val

Which actually changes the order twice, getting the original order back.

If some of the last 30 records were deleted and the id is auto-incremental you would get less than 30 results.
–
OhCaNMar 19 '12 at 19:53

4

Yeah, that's a big maybe, especially if there are gaps between ids. ORDER BY clause is the pro solution, nothing less nothing more.
–
ShefMar 19 '12 at 19:53

2

This answer assumes a lot about the composition of the table.
–
Brian DriscollMar 19 '12 at 19:54

1

This is not the best solution. As mentioned by Shef and other ORDER BY is the way to go. But there was this limitation from question "... without changing the order".
–
tonymarschallMar 19 '12 at 19:58

Nothing is said about an order, so you can not use ORDER BY.
There is a way to get records from a given point, but for that you need to know how many records there are, then use this counted value to provide the limits