MySql如何在表中显示具有最新ID的记录?
让我们首先创建一个表-
mysql> create table DemoTable676(Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,
Number int
);
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable676(Number) values(1000);mysql> insert into DemoTable676(Number) values(1839);
mysql> insert into DemoTable676(Number) values(29894);
mysql> insert into DemoTable676(Number) values(1264);
mysql> insert into DemoTable676(Number) values(190);
mysql> insert into DemoTable676(Number) values(167);
使用select语句显示表中的所有记录-
mysql> select *from DemoTable676;
这将产生以下输出-
+----+--------+| Id | Number |
+----+--------+
| 1 | 1000 |
| 2 | 1839 |
| 3 | 29894 |
| 4 | 1264 |
| 5 | 190 |
| 6 | 167 |
+----+--------+
6 rows in set (0.00 sec)
以下是查询以在表中显示具有最新ID号的记录-
mysql> select *from DemoTable676 order by Id DESC LIMIT 1;
这将产生以下输出-
+----+--------+| Id | Number |
+----+--------+
| 6 | 167 |
+----+--------+
1 row in set (0.00 sec)
以上是 MySql如何在表中显示具有最新ID的记录? 的全部内容, 来源链接: utcz.com/z/335306.html