Search code examples
mysqltimestamplast-insert-id

Is there an equivalent to LAST_INSERT_ID for timestamps?


I love the LAST_INSERT_ID() function of MySQL. I use it all the time to retrieve the id of the just inserted row to return from my stored procedure afterwards. However, now I have a table which has a TIMESTAMP as Primary Key that is set to DEFAULT CURRENT_TIMESTAMP. How can I retrieve this last inserted timestamp?


Solution

  • This should do it safely:

    START TRANSACTION;
    {do your insert};
    SELECT MAX({timestamp field}) FROM {table};
    COMMIT;