00 Votes

SQLite: What is the ID of the last inserted row?

Info by SmartUser | 2013-11-07 at 20:21

Question: We have added a new row into a SQLite database using an INSERT statement. Now we need the ID of the last inserted row to use it in another statement or to store it somewhere else.

Solution: SQLite is providing the function last_insert_rowid() returning the ID of the last inserted row. Here is an example:

SELECT last_insert_rowid() FROM tab

Suppose our table is named "tab" and we have just added a new entry into this table. In this case, the request from above provides us the ID of this last entry.

ReplyPositiveNegative

About the Author

AvatarThe author has not added a profile short description yet.
Show Profile

 

Related Topics

SQLite: Reset AUTOINCREMENT

Question | 1 Answer

Important Note

Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.

Participate

Ask your own question or write your own article on askingbox.com. That’s how it’s done.