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
Link to comment
Share on other sites

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.
I guess another method would be using timestamps.
Link to comment
Share on other sites

[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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.