SQL:查询的默认“排序依据"是什么? [英] SQL: What is the default Order By of queries?

查看:133
本文介绍了SQL:查询的默认“排序依据"是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不使用ORDER BY时查询的默认顺序是什么?

What is the default order of a query when no ORDER BY is used?

推荐答案

不存在此类命令.取自 http://forums.mysql.com/read.php ?21,239471,239688#msg-239688

There is no such order present. Taken from http://forums.mysql.com/read.php?21,239471,239688#msg-239688

  • 缺少ORDER BY时,不要依赖顺序.

  • Do not depend on order when ORDER BY is missing.

如果需要特定的订单,请始终指定ORDER BY-在某些情况下,引擎可以消除ORDER BY,因为它的方式 做其他步骤.

Always specify ORDER BY if you want a particular order -- in some situations the engine can eliminate the ORDER BY because of how it does some other step.

SELECT * FROM tbl-这将执行表扫描".如果表有 从未有过任何DELETE/REPLACE/UPDATE,记录将恰好是 按插入顺序排列,因此可以观察到.

SELECT * FROM tbl -- this will do a "table scan". If the table has never had any DELETEs/REPLACEs/UPDATEs, the records will happen to be in the insertion order, hence what you observed.

如果您对InnoDB表执行了相同的语句,则它们会 已按PRIMARY KEY顺序而不是INSERT顺序交付.再次, 这是基础实现的产物,而不是 依靠.

If you had done the same statement with an InnoDB table, they would have been delivered in PRIMARY KEY order, not INSERT order. Again, this is an artifact of the underlying implementation, not something to depend on.

这篇关于SQL:查询的默认“排序依据"是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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