| 
                         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. 
                         (编辑:莱芜站长网) 
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! 
                     |