具体 *** 作:MYSQL获取自增ID的四种方法
select max(id) from tablename
SELECT LAST_INSERT_ID() 函数
LAST_INSERT_ID 是与table无关的,如果向表a插入数据后,再向表b插入数据,LAST_INSERT_ID会改变。
mysql>select * from a+-----+
| col |
+-----+
| 0 |
| 1 |
| 2 |
| 3 |
| 4 |
| 5 |
| 6 |
| 7 |
+-----+
8 rows in set (0.00 sec)
mysql>set @i := 0select @i := @i + 1 as `order`, a.* from a order by col desc
+-------+-----+
| order | col |
+-------+-----+
| 1 | 7 |
| 2 | 6 |
| 3 | 5 |
| 4 | 4 |
| 5 | 3 |
| 6 | 2 |
| 7 | 1 |
| 8 | 0 |
+-------+-----+
8 rows in set (0.00 sec)
mysql>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)