MySQL-返回表中的最后3个结果 [英] Mysql - return last 3 results in table

查看:147
本文介绍了MySQL-返回表中的最后3个结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有一种简单的方法,仅用一条sql语句返回表中的最后三个结果,但是按该顺序,即如果有盘旋的结果,它将以98、99、100的顺序返回,而不是只需按ID DESC和限制3排序即可,返回顺序为100、99、98

i was wondering if there was an easy way with just an sql statement to return the last three results in the table but in that order i.e. if there are a hundered results it would return in the order of 98, 99, 100 not simply ordering by id DESC and limit 3 which would return in order 100, 99, 98

非常感谢您的帮助.

p.s.在这种情况下,可以说我不知道​​结果的数量,也不是真的想发送2个sql请求只是为了找到数量(对于任何OFFSET答案).

p.s. in this instance, lets say I don't know the amount of results and don't really want to send 2 sql requests just to find the amount ( for any OFFSET answers ).

推荐答案

一种方法是使用DESC,然后再次对其进行排序:

One way would be to use DESC and then just sort them again:

SELECT * FROM (SELECT * FROM some_table ORDER BY id DESC LIMIT 3) a ORDER BY id

这篇关于MySQL-返回表中的最后3个结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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