Jump to content

How to fetch last entered record from the databse..??


Recommended Posts

i have problem fetching last record from the database...

i'm using a auto increment id column in my table and in that column i'm updating values time to time...so i cannot use ORDER BY id DESC..besides i cannot use another auto increment column in MYSQL ddatabase to use the above query....

can anybody tell me how to do it?? :confused:

The last record entered (INSERTED) can be found using the ORDER BY id DESC ... However, if what you want is the last record UPDATED, you would need to have a column that holds the date/time that the record was updated.

 

If you use a mysql TIMESTAMP (not to be confused with a Unix Timestamp) you can set it up so that it will automatically be updated when you do an UPDATE query - http://dev.mysql.com/doc/refman/5.0/en/timestamp.html

i'm using a auto increment id column in my table and in that column i'm updating values time to time...so i cannot use ORDER BY id DESC..

 

I presume that you are concerned that another system / page may have inserted a record before you try and retrieve it.

 

You can use mysql_insert_id to get the last row you inserted.

 

All the best

 

Keith

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.