The order of select results

 show variables like "%storage_engine%";
+----------------------------+--------+
| Variable_name              | Value  |
+----------------------------+--------+
| default_storage_engine     | InnoDB |
| default_tmp_storage_engine |        |
| enforce_storage_engine     |        |
| storage_engine             | InnoDB |
+----------------------------+--------+
4 rows in set (0.00 sec)

Why is it not sorted in the order of id?

MariaDB [roll]> select id,stu_id from student;
+-----+--------------+
| id  | stu_id       |
+-----+--------------+
|   1 | 201702070220 |
|   2 | 201702070227 |
|   3 | 201702070304 |
|   4 | 201702070310 |
|   5 | 201702070314 |
|   6 | 201702070320 |
|   7 | 201702070333 |
|   8 | 201702070334 |
|   9 | 201704010225 |
|  10 | 201704020103 |
|  11 | 201602060211 |
|  12 | 201605020114 |
|  13 | 201605080129 |
|  14 | 201603090120 |
|  15 | 201605080238 |
|  16 | 201705020129 |
|  17 | 201705020130 |
|  18 | 201605070108 |
|  19 | 201705030114 |
|  20 | 201705030123 |
|  21 | 201603020113 |
|  22 | 201702010101 |
|  23 | 201703020123 |
|  24 | 201701050106 |
|  25 | 201701050107 |
|  26 | 201701070129 |
|  27 | 201701020212 |
|  28 | 201503060102 |
|  29 | 201503060105 |
|  30 | 201703010107 |
| 107 | 201602050139 |
| 106 | 201602050138 |
| 105 | 201602050137 |
| 104 | 201602050136 |
| 103 | 201602050135 |
| 102 | 201602050134 |
| 101 | 201602050133 |
| 100 | 201602050132 |
|  99 | 201602050131 |
|  98 | 201602050129 |
|  97 | 201602050128 |
|  96 | 201602050127 |
|  95 | 201602050126 |
|  94 | 201602050125 |
|  93 | 201602050124 |
|  92 | 201602050123 |
|  91 | 201602050122 |
|  90 | 201602050121 |
|  89 | 201602050120 |
|  88 | 201602050119 |
|  87 | 201602050118 |
|  86 | 201602050117 |
|  85 | 201602050116 |
|  84 | 201602050114 |
|  83 | 201602050113 |
|  82 | 201602050112 |
|  81 | 201602050111 |
|  80 | 201602050110 |
|  79 | 201602050109 |
|  78 | 201602050108 |
|  77 | 201602050107 |
|  76 | 201602050105 |
|  75 | 201602050104 |
|  74 | 201602050103 |
|  73 | 201602050102 |
|  72 | 201602050101 |
| 108 | 201602050140 |
| 109 | 201602050141 |
| 110 | 201601040110 |
| 111 | 201602040103 |
| 112 | 201602060228 |
| 113 | 201602060205 |
+-----+--------------+
72 rows in set (0.00 sec)

id is the primary key

CREATE TABLE student (
id int (3) NOT NULL AUTO_INCREMENT COMMENT "key id",
stu_id varchar (14) NOT NULL COMMENT" student ID",
class varchar (10) NOT NULL COMMENT "class",
stu_name varchar (10) NOT NULL COMMENT "name"
PRIMARY KEY ( id ),
) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8

Sep.16,2021

because you have no order,mysql and no default order,. If you want to sort by id, you need to manually add order by id


If multiple rows have identical values in the ORDER BY columns, the server is free to return those rows in any order, and may do so differently depending on the overall execution plan. In other words, the sort order of those rows is nondeterministic with respect to the nonordered columns.

the Order by field in the document has the same value, and the order of the returned results is uncertain, especially inferred that order by null

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b41cda-3498b.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b41cda-3498b.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?