Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

last inserted row in mysql

Tags:

php

mysql

I executed a query which will insert an image link and username into a table:

INSERT into pictures set src = 'image link', username = 'acc'

I want to display that image after the query is executed (from table), or to get ID (I tried mysql_insert_id(), but what if 3 or more users will execute the query at the same time, which id will I get?

Thanks.

like image 683
John Avatar asked Apr 27 '11 20:04

John


People also ask

How do I get the latest inserted row in MySQL?

If you are AUTO_INCREMENT with column, then you can use last_insert_id() method. This method gets the ID of the last inserted record in MySQL.

How do I get the last inserted id in MySQL?

If you insert a record into a table that contains an AUTO_INCREMENT column, you can obtain the value stored into that column by calling the mysql_insert_id() function.

How do I get the last row in SQL?

The LAST() function in Structured Query Language shows the last value from the specified column of the table.


1 Answers

It gets the last ID from your database session, so if other users insert, that does not matter :D.

As long as your session does not do other insert (thats quite unlikely in mosts systems) in between you're fine

like image 106
Nanne Avatar answered Oct 16 '22 23:10

Nanne