加入收藏 | 设为首页 | 会员中心 | 我要投稿 湖南网 (https://www.hunanwang.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程 > 正文

有没有步伐从MySQL表中获取最后N行而不行使自动增量字段或时刻戳

发布时间:2021-04-01 14:08:24 所属栏目:编程 来源:网络整理
导读:stackoverflow自己有很多办理方案,其方针是行使自动增量字段或时刻戳读取表的最后n行:譬喻,以下查询以降序从名为tab的表中获取最后10个记录名为id的字段值,它是表中的自动增量字段: Select * from tab order by id desc limit 10 我的题目是:是否有任何替

stackoverflow自己有很多办理方案,其方针是行使自动增量字段或时刻戳读取表的最后n行:譬喻,以下查询以降序从名为tab的表中获取最后10个记录名为id的字段值,它是表中的自动增量字段:

Select * from tab order by id desc limit 10

我的题目是:是否有任何更换要领,而无需得到自动增量字段或时刻戳来完成使命以得到沟通的输出?

提醒:提出这个题目的念头来自以下究竟:我们将记录存储到表中,并在行使简朴查询查询数据库时未指定任何尺度,譬喻:

Select * from tab

然后输出的次序与插入表中的记录次序沟通.那么有没有步伐凭证与输入数据库相反的次序获取记录? 最佳谜底

In the SQL world,order is not an inherent property of a set of data.
Thus,you get no guarantees from your RDBMS that your data will come
back in a certain order — or even in a consistent order — unless you
query your data with an ORDER BY clause.

因此,假如您没有按某些ID或某些列排序的数据,则无法按照其排序跟踪数据.因此无法担保MYSQL怎样存储数据,因此您无法得到最后n笔记录.

您还可以查察此article:

Caveats

Ordering of Rows

In the absence of ORDER BY,records may be returned in a different
order than the previous MEMORY implementation.

This is not a bug. Any application relying on a specific order without
an ORDER BY clause may deliver unexpected results. A specific order
without ORDER BY is a side effect of a storage engine and query
optimizer implementation which may and will change between minor MySQL
releases.

(编辑:湖南网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    热点阅读