Is there a way to get last inserted id of a NON - auto incremented column in MySQL?

前端 未结 7 1360
别跟我提以往
别跟我提以往 2020-12-17 14:24

I know how LAST_INSERT_ID() works for auto incremented columns, but I cannot find a way to get the last id I inserted for a non auto incremented column.

Is there a

7条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-17 15:01

    you can easily do that using the same LAST_INSERT_ID().

    INSERT INTO thetable (id, value)
    VALUES (LAST_INSERT_ID(126), 'some data');
    
    SELECT LAST_INSERT_ID();  -- returns 126
    

提交回复
热议问题