MySQL select上次插入的数据id

mysql> select * from table1;
+----+------+-----------+
| id | name | addr      |
+----+------+-----------+
|  1 | Tom  | Beijing   |
|  2 | Lee  | 123       |
|  3 | Lee  | 123       |
|  4 | wu   | chongqing |
+----+------+-----------+
4 rows in set (0.00 sec)

mysql> insert into table1(name, addr) values("feng", "chengdu");
Query OK, 1 row affected (0.00 sec)

mysql> select last_insert_id;
ERROR 1054 (42S22): Unknown column 'last_insert_id' in 'field list'
mysql> select last_insert_id();
+------------------+
| last_insert_id() |
+------------------+
|                5 |
+------------------+
1 row in set (0.00 sec)

mysql> select last_insert_id() as lastid;
+--------+
| lastid |
+--------+
|      5 |
+--------+
1 row in set (0.00 sec)

mysql> 

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

开始在上面输入您的搜索词,然后按回车进行搜索。按ESC取消。

返回顶部