mysql默认排序问题

大致意思为,一个myisam引擎表在没有任何的删除,修改操作下,执行 select 不带order by,那么会按照插入顺序进行排序。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 ...
mysql默认排序问题
参考mysql官方的回答:
当你的表示myisam时:
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.
大致意思为,一个myisam引擎表在没有任何的删除,修改操作下,执行 select 不带order by,那么会按照插入顺序进行排序。

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.
对于innodb引擎表来说,在相同的情况下,select 不带order by,会根据主键来排序,从小到大2013-02-21
mengvlog 阅读 28 次 更新于 2025-08-08 11:36:20 我来答关注问题0
  • 1. 默认排序规则 当执行一个 SQL 查询时,如果没有指定 ORDER BY 子句,MySQL 会按照结果集中的列值升序排列。这意味着结果集会按照表中第一列的值,从小到大进行排序。2. 指定排序列和方向 如果你想按照特定的列进行排序,可以使用 ORDER BY 子句。例如,ORDER BY column_name 会按照 column_name...

  •  翡希信息咨询 关于MySQL的枚举字段排序问题

    根据枚举索引下标进行排序:默认情况下,MySQL会按照枚举下标的顺序对枚举字段进行排序。例如,如果枚举选项为 ‘A’, ‘B’, ‘C’,则会按照下标 ‘1’, ‘2’, ‘3’ 的顺序进行排序。优点:这种排序方式简单直接,且查询操作通常...

  • 单字段排序:当只指定一个字段进行排序时,MySQL默认按照该字段的升序排列数据。例如,SELECT * FROM table_name ORDER BY 字段1; 会按照字段1的升序排列结果集。多字段排序:当指定多个字段进行排序时,MySQL会首先按照第一个字段进行排序。如果第一个字段的值相同,则会按照第二个字段进行排序,以此类...

  • 升序排序:使用ASC关键字,这是ORDER BY子句的默认排序方式。例如,SELECT * FROM table_name ORDER BY column_name ASC;。降序排序:使用DESC关键字。例如,SELECT * FROM table_name ORDER BY column_name DESC;。多列排序:在ORDER BY子句中,可以列出多个列名进行排序,列名之间用逗号分隔。MySQL会...

  • 大致意思为,一个myisam引擎表在没有任何的删除,修改操作下,执行 select 不带order by,那么会按照插入顺序进行排序。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 ...

檬味博客在线解答立即免费咨询

mySQL相关话题

Copyright © 2023 WWW.MENGVLOG.COM - 檬味博客
返回顶部