SQL: What is the default Order By of queries?(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 -- 这将执行表扫描".如果表有从来没有任何 DELETEs/REPLACEs/UPDATEs,记录将恰好是在插入顺序中,因此您观察到了什么.
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:查询的默认排序依据是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:SQL:查询的默认排序依据是什么?
基础教程推荐
- SQL Server 实例在登录协商期间返回无效或不受支持的协议版本 2021-01-01
- SQL:使用来自具有相同列名的两个表中的数据... 2021-01-01
- 是否可以执行按位分组功能? 2021-01-01
- SQL 效率:WHERE IN 子查询 vs. JOIN 然后 GROUP 2021-01-01
- SSMS 中的权限问题:“对象 'extended_properties'、数据库 'mssqlsystem_resource'、... 错误 229)上的 SELECT 权限被拒绝" 2022-01-01
- 在 SQL 中连接多个表 2021-01-01
- 需要 MySQL 5.1 中的抽象触发器来更新审计日志 2021-01-01
- 无法解决整理冲突 2021-01-01
- 将 SQL Server DateTime 列迁移到 DateTimeOffset 2021-01-01
- 如何使用 mysql.connector 禁用查询缓存 2022-01-01
