SQL, select last insert ID by LAST_INSERT_ID()

user3629794

I didn't find an exact answer so I try to ask here. I running an SQL INSERT Query and after that I want to use the ID of the this INSERT Query, I found this: LAST_INSERT_ID() and it's work, but I thinking what would happen if I not the only one who run the query on the server I can get a wrong ID from the DB, so there is other to take the last ID ?

Vivek Vaghela

It should return the last inserted row id from the same connection. So if other user has inserted another row in between, LAST_INSERT_ID function will still return the relevant idfor the first user.

Quoting from mysql documentation:

The ID that was generated is maintained in the server on a per-connection basis. This means that the value returned by the function(LAST_INSERT_ID) to a given client is the first AUTO_INCREMENT value generated for most recent statement affecting an AUTO_INCREMENT column by that client

Here is the link http://dev.mysql.com/doc/refman/5.0/en/information-functions.html#function_last-insert-id .

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

how to select last_insert_id?

From Dev

SELECT LAST_INSERT_ID() not generating correctly

From Dev

SELECT LAST_INSERT_ID() returning zero

From Dev

SQL Add a prefix to LAST_INSERT_ID()

From Dev

Thread safety of MySQL's Select Last_Insert_ID

From Dev

Using select last_insert_id() from php not working

From Dev

Both sql LAST_INSERT_ID() and PHP insert_id return 0

From Dev

MySQL SQL_INSERT_ID() and LAST_INSERT_ID do not work

From Dev

How efficient is Last_insert_id?

From Dev

MYSQL last_insert_id() and concurrency

From Dev

LAST_INSERT_ID after restarting MySQL

From Dev

MYSQL last_insert_id() and concurrency

From Dev

use of where cluase for last_insert_id

From Dev

Java Spring JDBC last_insert_id()

From Dev

MariaDB Columnstore LAST_INSERT_ID() alternative

From Dev

How to do a multiple insert using LAST_INSERT_ID() MySQL?

From Dev

Invalid descriptor index on LAST_INSERT_ID after insert

From Dev

How to do a multiple insert using LAST_INSERT_ID() MySQL?

From Dev

Is it possible to get LAST_INSERT_ID() from different database?

From Dev

MySQL LAST_INSERT_ID() - how does it works

From Dev

MySQL : Stored procedure returns null for last_insert_id

From Dev

MySQL retrieve last_insert_id from stored procedure

From Dev

how to get LAST_INSERT_ID via stored procedure in php

From Dev

MySQL: Can't get LAST_INSERT_ID()

From Dev

Explain to me exactly what last_insert_id(expr) does

From Dev

why does LAST_INSERT_ID() returns foreign key

From Dev

MySQL Function with LAST_INSERT_ID() giving unexpected results

From Dev

PDO not being able to return the last_insert_id

From Dev

Can't get last_insert_id from database with Eloquent

Related Related

HotTag

Archive