U
U
Urukhayy2015-11-07 14:18:10
MySQL
Urukhayy, 2015-11-07 14:18:10

Can an INSERT query return the id of the inserted row?

You need to write a query that inserts data and returns the auto-increment id of the newly inserted row. The construction - "INSERT ...... ; SELECT ....." is not suitable.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Mikhail Osher, 2015-11-07
@miraage

dev.mysql.com/doc/refman/5.7/en/information-functi...

INSERT INTO sometable VALUES (1, 2);
SELECT * FROM othertable WHERE uid = LAST_INSERT_ID();

A
Alexander Aksentiev, 2015-11-07
@Sanasol

procedure?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question