If you want to get the IDs of the latest updated rows it during a query you can do something like that
If the rows have already been updated via other queries that you are not aware of you, as far as I know, you must have a column (ex. lastmodified) in the database that must be updated each time that you do modifications.
To have *automatic* modifications it's better to use the triggers, if supported by your mysql version. (https://dev.mysql.com/doc/refman/5.0/en/create-trigger.html )
After that you can select any recent modified thing
example:
SET @updatedrows := null; /*we will store here the IDs*/
UPDATE mytable SET coltoupdate = 'mycontent' WHERE myID > 5 AND (SELECT @updatedrows := CONCAT_WS(', ', myID, @updatedrows));
SELECT @updatedrows; /*shows the updated IDs*/
If the rows have already been updated via other queries that you are not aware of you, as far as I know, you must have a column (ex. lastmodified) in the database that must be updated each time that you do modifications.
To have *automatic* modifications it's better to use the triggers, if supported by your mysql version. (https://dev.mysql.com/doc/refman/5.0/en/create-trigger.html )
/*adding the lastmodified col to the table*/
ALTER TABLE mytable ADD lastmodified DATETIME NOT NULL;
/*creating the trigger*/
CREATE TRIGGER updatelastmodified BEFORE UPDATE ON `mytable ` FOR EACH ROW SET NEW.lastmodified = NOW();
After that you can select any recent modified thing
example:
SELECT * FROM mytable ORDER BY lastmodified DESC LIMIT 5; /*for the latest 5 modified - you can also concat them as before and reuse in other queries*/
Comments
Post a Comment