Copy Newest Timestamp to Another Table

  mysql, mysqli, php

I want to copy the newest timestamp with data type "DATETIME" of my data to the another table each time newest data inserted

Source Table (table1) :

id task_id inq_dt status
1 11111 2021-09-25 08:33:04 ok
2 11111 2021-09-25 08:35:14 ok
3 22222 2021-09-25 08:36:54 ok
4 11111 2021-09-25 08:38:34 ok
5 22222 2021-09-25 08:40:39 ok

Target Table (table2):

id task_id last_inqdt
1 11111 2021-09-25 08:38:34
2 22222 2021-09-25 08:40:39

Both inq_dt and last_inqdt type is "DATETIME"

I’ve tried using something like this

UPDATE table2
SET last_inqdt = GetDate()
FROM table1
where table2.task_id = table1.task_id

with trigger config
AFTER INPUT table1

But it’s doesn’t work, any idea?

Source: Ask PHP

LEAVE A COMMENT