在现有 table 中插入新记录时,tt 上升而不是下降

When inserting new record in existing table tt goes up instead of down

我已经创建了 table 我想添加额外的行 添加额外的行时创建的额外的行上升。我想要底部的那一行。

MariaDB [armydetails]> insert into armydetails values('r05','Shishir','Bhujel','Jhapa','9845678954','male','1978-6-7','1994-1-3','ran5','Na11088905433');
Query OK, 1 row affected (0.17 sec)

MariaDB [armydetails]> select * from armydetails;
+-------+---------+---------+-----------+------------+--------+------------+------------+--------+----------------+
| regNo | fName   | lName   | address   | number     | gender | DOB        | DOJ        | rankID | accountNo      |
+-------+---------+---------+-----------+------------+--------+------------+------------+--------+----------------+
| r05   | Shishir | Bhujel  | Jhapa     | 9845678954 | male   | 1978-06-07 | 1994-01-03 | ran5   | Na11088905433  |
| ro1   | Milan   | Katwal  | Dharan    | 9811095122 | Male   | 1970-01-03 | 1990-01-01 | ran1   | Na11984567823  |
| ro2   | Hari    | Yadav   | Kathmandu | 9810756436 | male   | 1980-06-07 | 2000-05-06 | ran2   | Na119876678543 |
| ro3   | Khrisna | Neupane | Itahari   | 9864578934 | male   | 1980-02-02 | 2001-01-07 | ran3   | Na11954437890  |
| ro4   | Lalit   | Rai     | Damak     | 9842376547 | male   | 1989-05-09 | 2005-01-02 | ran4   | Na11064553221  |
+-------+---------+---------+-----------+------------+--------+------------+------------+--------+----------------+
5 rows in set (0.00 sec)

MariaDB [armydetails]>

SQL 2011 publication from ISO/IEC 9075 说:

In general, rows in a table are unordered; however, rows in a table are ordered if the table is the result of a that immediately contains an « order by clause ».

在 SQL 数据库中,记录没有基本的默认排序。关系数据库基本上将 table 存储为一堆无序记录。

当记录在没有 ORDER BY 子句的情况下被 SELECTed 时,它们以未定义的顺序出现,绝不能保证在后续查询中保持一致(包括正在执行的相同查询)多次执行)。 MySQL 对于其他 RDBMS 也是如此。

正确排序记录的唯一方法是使用 ORDER BY 子句,例如:

select * from armydetails order by regNo

建议的讲座:Tom Kyte Blog : Order in the Court!

您只需在语句中添加一个 ORDER BY 子句,如下所示:

SELECT * FROM armydetails ORDER BY regNO DESC;