My project contains 2 tables one is profile_table and another is address_table

Profile_ table contains:

| sid  | sname   | saddress |
|  1   | xyz     |   india  |
|  2   | abc     |     U.S  |

‘sid’ field in profile_table is made as primary key and autoincremented field.

The address table also contains 'sid':

| sid  | squalification    | smarks |
|  1   |    B.E            | 80     |
|  2   |    M.S            |  85    |
+------+------------------ +--------+

The sid column in 'address_table' is made as foreign key in the address table and when I inserted the first record in the profile_table that sid value must be inserted in the address_table along with squalification,smarks values.I want to use 'last inserted id' concept here and i dont want to use the stored procedure. please explain me how to get the last inserted id using scope identity without using a stored procedure in Mysql.


The LAST_INSERT_ID() function will return what you are looking for. It is a built-in function, does that qualify?

I'm not sure what you mean by excluding "stored procedure"; maybe it's just wrong terminology and you wish to also exclude built-in functions?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.