如何从mysql中的表中选择最后N条记录 [英] How to select last N records from a table in mysql

查看:142
本文介绍了如何从mysql中的表中选择最后N条记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此代码可用于从mysql表中选择前十条记录.如何执行相同的操作以显示具有1000条记录的表中的最后十条记录.我想按升序显示名称,但不想更改.

This code can be used to select the first ten records from a table in mysql. How can I do the same to display last ten records from a table which has 1000 records. I want to display the name in asc order dont want to change that.

   SELECT name, cost FROM test orderby name asc LIMIT 10 ;

推荐答案

SELECT q.name, q.cost
    FROM (SELECT name, cost
              FROM test
              ORDER BY name DESC LIMIT 10) q
    ORDER BY q.name ASC;

这篇关于如何从mysql中的表中选择最后N条记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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