在不更改表结构的情况下选择表中最后n行的最有效方法是什么? [英] What's the most efficient way to select the last n rows in a table without changing the table's structure?

查看:58
本文介绍了在不更改表结构的情况下选择表中最后n行的最有效方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用mySQL在表中选择最后n行的最有效方法是什么?该表包含数百万行,在任何给定时间,我都不知道该表有多大(它一直在增长).该表确实具有一列,该列会自动递增,并用作每一行的唯一标识符.

What's the most efficient way to select the last n number of rows in a table using mySQL? The table contains millions of rows, and at any given time I don't know how large the table is (it is constantly growing). The table does have a column that is automatically incremented and used as a unique identifier for each row.

推荐答案

SELECT * FROM table_name ORDER BY auto_incremented_id DESC LIMIT n

这篇关于在不更改表结构的情况下选择表中最后n行的最有效方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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