Very generally, add a timestamp column which is automatically set on the insert, perhaps using a trigger. Then have an update trigger which sets either another timestamp column and/or a flag (i.e. Boolean) column that indicates when a modification has occurred. Or perhaps even better, just have the update trigger record the log event directly.
There are multiple ways to accomplish this, but I have modeled my timestamp columns after this other SO answer.
Here is just one example of a trigger that directly records into the log. Oh, this syntax is for sqlite because I prepared it before I realized that the tags changed. I'm not sure if this is compatible with MySQL:
CREATE TRIGGER update_log_trigger
AFTER UPDATE ON vrp_user_moneys
WHERE (NEW.wallet > 4000000 OR NEW.bank > 8000000)
BEGIN
INSERT INTO log_de_money (user_id, wallet, bank)
VALUES (NEW.user_id, NEW.wallet, NEW.bank);
END;
Do you understand how this will record the log rows automatically, without having to run a timed query?
If you insist on running a timed query (every 2 seconds), then you need to add other columns to help determine what has changed and what has not changed, just like I already mentioned.
Here is some pseudo-SQL to demonstrate the sequence in the question. Here I will NOT use automatic timestamps, rather will demonstrate with a manual change-flag column. Problems may occur if the timed queries happen to run before changed columns are properly updated. (Using triggers and appropriate transactions could solve this problem.):
INSERT INTO vrp_user_moneys (user_id, wallet, bank, isChanged)
VALUES (@user_id, @newWalletValue, @newBankValue, false);
Later an update happens ...
UPDATE vrp_user_moneys
SET wallet = @updatedWalletValue, isChanged = true
WHERE user_id = @user_id;
Logging script executes ...
BEGIN TRANSACTION;
INSERT INTO log_de_money (user_id, wallet, bank)
SELECT user_id, wallet, bank
FROM vrp_user_moneys
WHERE (wallet > 4000000 OR bank > 8000000)
AND isChanged = true;
UPDATE vrp_user_moneys
SET isChanged = false
WHERE (wallet > 4000000 OR bank > 8000000)
AND isChanged = true;
COMMIT TRANSACTION;