mysql - offset problem

时光怂恿深爱的人放手 提交于 2019-12-06 13:24:40

According to the MySQL Documentation:

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:

They recommend you use a query such as:

SELECT * FROM tbl LIMIT 95,18446744073709551615;

So in your case, you should try:

SELECT *
FROM (SELECT * 
      FROM $table 
      ORDER BY ID DESC 
      LIMIT 3,18446744073709551615) AS T 
ORDER BY TIME_STAMP

Note that you can also use the PostgreSQL compatible version using the keyword OFFSET:

SELECT *
FROM (SELECT * 
      FROM $table 
      ORDER BY ID DESC 
      LIMIT 18446744073709551615 OFFSET 3) AS T 
ORDER BY TIME_STAMP

Just in case you are wondering, 18446744073709551615 = 2^64 - 1.

You can't use OFFSET without a LIMIT.

A little bulky, but that query worked for me, and not worked without an redundant internal subquery (mysql 5.0.90)

select * from $table 
where id not in (
  select id from (
    select id from languages order by id DESC LIMIT 3
  ) l1
) order by time_stamp

Was having the same issue because I copied:

OFFSET :offset LIMIT :limit

from an existing query, which is valid in Postgres.

Apparently the order matters in MySQL, so reversing the order worked for me:

LIMIT :limit OFFSET :offset 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!