SQL:查询的默认顺序是什么?

SQL: What is the default Order By of queries?(SQL:查询的默认顺序是什么?)
本文介绍了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:查询的默认顺序是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Can#39;t Create Entity Data Model - using MySql and EF6(无法创建实体数据模型 - 使用 MySql 和 EF6)
MySQL select with CONCAT condition(MySQL选择与CONCAT条件)
Capitalize first letter of each word, in existing table(将现有表格中每个单词的首字母大写)
How to retrieve SQL result column value using column name in Python?(如何在 Python 中使用列名检索 SQL 结果列值?)
Update row with data from another row in the same table(使用同一表中另一行的数据更新行)
Exporting results of a Mysql query to excel?(将 Mysql 查询的结果导出到 excel?)