Jump to content

Getting the lasted added record from MySQL


ChrisMartino

Recommended Posts

Hello there, I'm wondering if somebody can help me, I am trying to retrieve the last added record from a MySQL database so i can get information from it, But i don't know how to get the last record, Just the last added record to the database, Dose anybody know how to do this?.

 

Thanks for your time,

Chris.

It might be worth checking out mysql_insert_id at http://php.net/manual/en/function.mysql-insert-id.php

 

I'm not sure if it only returns an ID if your script was the one actually doing the inserting or not, though.

 

EDIT: Disregard, it only appears to work on queries executed within your same script execution

Using query Ken2k7 gave you you will indeed get last record in the table on the assumption, that the record with highest ID is the latest. This is not always true however, so if you really want to be sure, you should be timestamping your rows.

 

mysql_insert_id() (or MySQL's LAST_INSERT_ID() ) functions will only give you an ID of last record insert during current connection and even this only if it was a single row insert. See MySQL's manual for more information.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.