· 8 years ago · Jul 25, 2018, 03:52 PM
1drop table if exists tbl;
2
3create table tbl (
4 id int primary key AUTO_INCREMENT,
5 valor int not null,
6 texto varchar(50) not null
7);
8
9insert into tbl (valor, texto) values (1, 'aaa');
10insert into tbl (valor, texto) values (5, 'eee');
11insert into tbl (valor, texto) values (2, 'bbb');
12insert into tbl (valor, texto) values (4, 'ddd');
13insert into tbl (valor, texto) values (3, 'ccc');
14
15select *
16 from tbl
17 order by id desc
18 limit 1;
19
20drop table tbl;
21
22INSERT INTO tbl (texto) values ('eee');
23SELECT LAST_INSERT_ID();