PDA

View Full Version : Simply MySQL question



kj1h234lkj1234
January 8th, 2007, 07:44 AM
In the past, I've had to insert a row into a database, then use the row ID of the newly-inserted row in another query.

In Access, if I recall, you could do something like this:


INSERT INTO `blah` (id, comment) VALUES('', 'blahblah');

Then to get the id of the row I just inserted, it was something like:


SELECT @@identity FROM `blah`(or something like that)

Anyone have any idea what that's called, or how to do it in MySQL?

Thanks

Wim Sturkenboom
January 8th, 2007, 09:35 AM
check the mysql manual for last_insert_id()
from the manual:

mysql> SELECT LAST_INSERT_ID();
-> 195

kj1h234lkj1234
January 8th, 2007, 01:33 PM
Awesome, thanks a lot!

Apparently LAST_INSERT_ID() and @@IDENTITY and exactly the same thing.

*slaps self* :rolleyes: