Mysql从表的前50条记录中选择最后5条记录


mysql select last 5 records from first 50 records in the table

我想从表中的前50条记录中选择最后5条记录,目前我有以下查询,有人告诉我最好的方法来选择这些记录而不计算限制和偏移量?

SELECT id FROM table WHERE enabled=1 ORDER BY date LIMIT 5, 45

试试这个

SELECT id FROM (SELECT id FROM (SELECT id FROM table ORDER BY id ASC LIMIT 50) AS tbl ORDER BY id DESC LIMIT 5) as tbldata ORDER BY id ASC 

这行得通:

SELECT id FROM (SELECT id,date FROM ORDER BY date LIMIT 50诱人的订单日期DESC限制5