Skip to main content

Get the ID of latest updated rows and automatically update latest modification timestamp

If you want to get the IDs of the latest updated rows it during a query you can do something like that

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

Popular posts from this blog

Moodle 3.8.1+ - path leak via errors in several files

Moodle 3.8.1+ ----------------------------------------------- File: admin/mailout-debugger.php #!/usr/bin/php Notice : Disabled. in \admin\mailout-debugger.php on line 73 File: admin/settings/appearance.php Notice : Undefined variable: hassiteconfig in \admin\settings\appearance.php on line 10 Fatal error : Uncaught Error: Call to undefined function has_any_capability() in \admin\settings\appearance.php:10 Stack trace: #0 {main} thrown in \admin\settings\appearance.php on line 10 File: admin/settings/badges.php Notice : Undefined variable: hassiteconfig in \admin\settings\badges.php on line 30 Fatal error : Uncaught Error: Call to undefined function has_any_capability() in \admin\settings\badges.php:30 Stack trace: #0 {main} thrown in \admin\settings\badges.php on line 30 File: admin/settings/courses.php Notice : Undefined variable: hassiteconfig in \admin\settings\courses.php on line 32 Fatal error : Uncaught Error: Call to undefined function

2022 - Remove (the too many) Ads from Memu launcher

Simple method Download from pureapk "MEmu Launcher2" ex: MEmu Launcher2_v6.0.9_apkpure.com Install "System app remover" (root) remove from system apps the "memu launcher 2" import the "purified" MEmu Launcher2 apk with the Memu utility ("apk" on the right toolbar) Longer method Install "Export Apk" Export the memu launcher2  Install purify https://github.com/echo-devim/purify/raw/master/Purify.apk use purify with the exported memu launcher 2 Install "System app remover" (root) remove from system apps the "memu launcher 2" import the "purified" MEmu Launcher2 apk with the Memu utility ("apk" on the right toolbar)