发布网友
共1个回答
热心网友
参考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,会根据主键来排序,从小到大追问我的id是自增的,也就是id大的就是后插入的。
这样的情况下,是不是不使用order by 默认就是按id排序?
追答是的,如果你没有对先前的列进行修改,不管是myisam或者是innodb,id自增长就是按照id来排