Jump to content

Getting last record -- Newbie question


creeker

Recommended Posts

You need to call LAST_INSERT_ID() immediately after an insert query to retrive the value of the auto_increment column in the table. It it returns the last id generated for the current connection.

I you come back to the table with a new connection (new page) then you can get the last record by

SELECT * FROM tablename ORDER BY id DESC LIMIT 1
[quote author=creeker link=topic=112849.msg458528#msg458528 date=1161952187]
I'm not using it to auto increment. I'm calling in from a site to find the last added record.
So "SELECT * FROM tablename ORDER BY id DESC LIMIT 1" seems a good method since the ID is auto_incremented.
[/quote]
You mean someone else inserted the record, and you're trying to find the last one?  Date/time would be more preferable, IMHO.

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.