如何在MySQL中获取行数据的max(id)?
要获取max(id),请使用MAX()
MySQL中的method。以下是语法-
select MAX(yourColumnName) AS anyAliasName from yourTableName;
让我们首先创建一个表-
mysql> create table DemoTable710 (Id int);
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable710 values(1001); mysql> insert into DemoTable710 values(2001); mysql> insert into DemoTable710 values(1998); mysql> insert into DemoTable710 values(1789); mysql> insert into DemoTable710 values(1678); mysql> insert into DemoTable710 values(9087); mysql> insert into DemoTable710 values(1908);
使用select语句显示表中的所有记录-
mysql> select *from DemoTable710;
这将产生以下输出-
+------+ | Id | +------+ | 1001 | | 2001 | | 1998 | | 1789 | | 1678 | | 9087 | | 1908 | +------+ 7 rows in set (0.00 sec)
以下是在MySQL中获取行数据的max(id)的查询-
mysql> select MAX(Id) AS Max_Id from DemoTable710;
这将产生以下输出-
+--------+ | Max_Id | +--------+ | 9087 | +--------+ 1 row in set (0.00 sec)