Getting last inserted id

MySQL provides the LAST_INSERT_ID() function to get the most recently inserted id for the current connection. Other connections' insertions will not be returned by this function:

mysql> SELECT LAST_INSERT_ID();
        -> 195

docs

View on Github