I would like to create an event that when a lend_date
column has passed exactly 15 days, it would execute an INSERT
query.
It would get the ID of that row and userid
, and insert it to another table.
For example:
id | userid | lend_date
---+----------+----------------------
1 | 1 | 2015-09-24 15:58:48
2 | 1 | 2015-09-21 08:22:48
And right now, it is exactly 2015-10-06 08:23:41
. So the event should get the ID of the second row, which is 2
, and insert it to another table.
What should my event query look like?
The event type is RECURRING
. But I'm also not sure if I should execute it every hour or everyday. What would be the best recommendation for it?
And is this a better way than using Task Scheduler
?
The other table that I wanted to insert the fetched ID is notification_table
, where it will notify the user that he/she has an overdue date.
notification_table
looks like this:
id | userid | notificationid | notificationdate |
---+----------+------------------+----------------------+
1 | 1 | 1 | 2015-09-24 15:58:48 |
2 | 1 | 1 | 2015-09-21 08:22:48 |
I'm looking at this query:
INSERT INTO notification_table (id, userid, notificationid, notificationdate)
SELECT id, userid, 1, NOW()
FROM first_table
WHERE lend_date + INTERVAL 15 DAY = NOW();