MySQL获取最后10条记录中的第一条记录 [英] MySQL Get the first record in the last 10 records

查看:992
本文介绍了MySQL获取最后10条记录中的第一条记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Mysql中,我试图获取最近10条记录中最旧的记录.

in Mysql, I am trying to get the oldest record of the last 10 records.

要获得最后的10个,我只会做 SELECT * FROM table ORDER BY id DESC LIMIT 10;

To get the last 10 I would simply do SELECT * FROM table ORDER BY id DESC LIMIT 10;

要获取最早的数据,我只需使用ASC顺序即可.

to get the oldest I simply use the ASC order.

我需要先按DESC顺序获得最后的10个,然后按ASC顺序获得该数组的第一个记录. 我将使用哪个查询以DESC顺序获取行号10,即最新的10条中的最旧的?

I need to first order in DESC order to get the last 10 and then order by ASC to get the first record of that array. which query would I use to get row number 10 in DESC order, namely, the oldest of the 10 newest?

推荐答案

使用这里,偏移量为9->表示第10行(按升序排列时将是最后10行中的第一行).

Here, OFFSET is 9 --> that means 10th row (which will be first row in the last 10 rows when ordered back in Ascending order).

这篇关于MySQL获取最后10条记录中的第一条记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆