Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How get the Id of inserted row in SQL [duplicate]

My database table has ID column which is an auto incremental integer. While inserting data to the table its increment automatically I need to get the value of ID when a record is inserted.

Eg: table employee = |ID| NAME | ADDRESS|

the query is :

insert into employee(NAME, ADDRESS) values("azzi", "test adress")

there is a possible that we can change this query to return the ID soon after record inserted, some one help me to do that.

like image 962
Azad Avatar asked Jul 27 '15 07:07

Azad


People also ask

How do I query duplicate rows in SQL?

To select duplicate values, you need to create groups of rows with the same values and then select the groups with counts greater than one. You can achieve that by using GROUP BY and a HAVING clause.


1 Answers

With the SQLite last_insert_rowid() function:

The last_insert_rowid() function returns the ROWID of the last row insert from the database connection which invoked the function.

like image 146
namezero Avatar answered Sep 22 '22 08:09

namezero