##this returns 1 and 1 from the sp. drop procedure if exists `p1`; drop table if exists `t1`; drop table if exists `t2`; create table `t1` (id int not null auto_increment primary key); create table `t2` (id int not null auto_increment primary key); insert into `t2` values (),(),(),(); delimiter // create procedure `p1`() begin insert into `t1` values (); select last_insert_id(); insert into `t2` values (); select last_insert_id(); end;// delimiter ; call `p1`(); ##this returns 1 and 5 correctly. drop table if exists `t1`; drop table if exists `t2`; create table `t1` (id int not null auto_increment primary key); create table `t2` (id int not null auto_increment primary key); insert into `t2` values (),(),(),(); insert into `t1` values (); select last_insert_id(); insert into `t2` values (); select last_insert_id();