Basically, I have a table where I store messages for each user. Each user is allocated 1,000 messages, by 30 days.
| id | user_id | message | created_at |
|---|---|---|---|
| 1 | 12 | ... | 2020-01-01 16:30:45 |
| 2 | 45 | ... | 2020-01-02 16:31:12 |
| 3 | 12 | ... | 2020-01-02 16:61:15 |
My intention is to run a single SQL statement to delete the exceeding messages of each user by quantity, and those older than 30 days.
The only solution I have so far is to get the user_id using a GROUP BY clause, and iterate over each with a subquery.