mohamad mohamad mohamad mohamad - 1 year ago 130
MySQL Question

how to get from database the last inset id before insert

How to select the last insert id from database table

i need to get the last insert id from database

i try the

function but this doesn't work for me because i want to get this id before i do an insert query and when i get this id i do an insert query

i try to use
for the id but this have a problem that if i have a deleted
id it will not be taken

example if i have id 10 deleted than the max id will be 9 but the auto
increment will be 11

than i want to have the new id that will be added by the auto increment

example:i have an id 10 deleted i want to take than next id it will be

Answer Source

You Can :

    WHERE TABLE_SCHEMA = 'database_name'
    AND   TABLE_NAME   = 'table_name';
And get your last id.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download