Hello!
Today for the first time I ran into ON DUPLICATE KEY UPDATE did not fully understand how it works.
I make a request
DB()->query("INSERT INTO ". BB_BT_USER_STATS ." (topic_id, user_id, date_comleted) SELECT topic_id, user_id, ". TIMENOW ." FROM tmp_users_stats ON DUPLICATE KEY UPDATE date_comleted = что тут писать"); As a result, I want to receive an update in the table if topic_id and user_id already exist (unique), and date_comleted is different, otherwise a new line is created with new data.