views:

126

answers:

1

Hi All,

Is there any way using which I can get the last row I have updated of the table.

For Ex:- my table has 1000 records in it. I have updated the value of 500th record of table X. So, I want the ID 500 in return.

Thanks in advance.

Regards,

+7  A: 

I don't think this feature exists with MySQL. However you can get the same effect by adding a timestamp column:

ALTER TABLE yourtable
   ADD COLUMN last_update TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP

This would make the last_update column pretty much automatically maintained. Now you can select from yourtable the last updated row based on the timestamp.

Alterlife
And... add an index to the last_update column.
gahooa
@gahooa Very true :) .
Alterlife
Thanks for the input. It is a great help.
MySQL DBA