Jump to content

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


mansoor323

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

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.