How to get the last insert ID from a table

Enrique San Martín picture Enrique San Martín · Jun 21, 2010 · Viewed 30.9k times · Source

I want to get the value of the last ID insert in a table. How I can do this?

Answer

Enrique San Martín picture Enrique San Martín · Jun 22, 2010

Well the solution that I use is:

select id from NEW TABLE (insert into (val1, val2, ...) values ('lorem', 'ipsum', ...))

This gets the id column from the last row inserted in the DB :)