不知道mysql>select a_id from a order by a_id desc limit 1;
是不是你想要的。

解决方案 »

  1.   

    还有一个last_insert_id()的函数,不过用起来有很多限制。
      

  2.   

    last_insert_id()函数返回向auto_increment字段中插入数据时由MySQL自动产生的最后一个id.
    当处理多个表之间的连接或者需要使用一个表的记录id作为另一个表的密钥时,使用这个函数就会比较方便。
    mysql> insert into t1(type) values('jimmy');
    Query OK, 1 row affected (0.00 sec)mysql> select last_insert_id();
    +------------------+
    | last_insert_id() |
    +------------------+
    |                5 |
    +------------------+
    1 row in set (0.11 sec)mysql>insert into dep values(55,last_insert_id());
    Query OK,1 row affected (0.03 sec)更加具体的用法可以查一查mysql 4.1.0中文参考手册---犬犬(心帆)翻译