mysql - SQL : What is the default Order By of queries?

标签 mysql

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

最佳答案

不存在这样的订单。取自 http://forums.mysql.com/read.php?21,239471,239688#msg-239688

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

  • 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.

  • GROUP BY forces ORDER BY. (This is a violation of the standard. It can be avoided by using ORDER BY NULL.)

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.

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.

关于mysql - SQL : What is the default Order By of queries?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8746519/

相关文章:

php - 来自 for 循环的多个 mysql 查询

php - 将数据库行放入关联数组的简单方法

php - 简写 IF/ELSE 条件 PHP - 我做错了什么?

php - 如何以html形式发送动态值?

MySQL JOIN 与 GROUP BY 需要很长时间才能运行

Php分页与MYSQL的区别

mysql - : mysql_fetch_row(res)之谜

mysql - 如何优化需要 10 秒才能获取结果的 MySQL 查询

mysql - 在 MySql 中创建行向上移动的新列

mysql - NPM MySql 连接需要在文件中分开