A
A
Andrey Astafiev2015-12-17 18:03:41
MySQL
Andrey Astafiev, 2015-12-17 18:03:41

How to make SELECT LAST_INSERT_ID() as id work?

SELECT LAST_INSERT_ID() as id
returns 0 all the time, although it should return the ID of the newly added entry

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Shamanov, 2015-12-17
@SilenceOfWinter

Firstly, the request is not complete, the table is not specified, and secondly, if an auto index is used, then it is easier to make a selection by id.
For example,

SELECT id FROM tbl_name ORDER BY id DESC LIMIT 0, 1

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question