我已经创建了表,我想在添加额外的行时添加额外的行,创建的额外行会上升。我希望该行位于底部。
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]>
答案 0 :(得分:1)
SQL 2011 publication from ISO/IEC 9075说:
通常,表中的行是无序的;但是,如果表的结果是立即包含«order by子句»的结果,则表中的行将被排序。
在SQL数据库中,记录没有基础的默认顺序。关系数据库基本上将一个表存储为一堆无序记录。
在没有SELECT
子句的情况下ORDER BY
记录时,它们以未定义的顺序出现,因此决不能保证在随后的查询中保持一致(包括执行相同的查询,次)。对于MySQL 和,对于其他RDBMS都是如此。
正确排序记录的唯一方法是使用ORDER BY
子句,例如:
select * from armydetails order by regNo
答案 1 :(得分:0)
您只需将ORDER BY子句添加到语句中,如下所示:
SELECT * FROM armydetails ORDER BY regNO DESC;