Got a simple php page pushing some data into a MySQL table.
The table is an activity log, and I’d like to keep just 30 days of activity for each user.
I figure I can create my INSERT SQL so it UPDATES any record it finds over 30 days old with the new data, and then the # of records will be more manageable.
Any tricky ways of creating an SQL query that does this:
If there’s no records for the user, add a new one
If there’s existing records for that user, see if any are >30 days.
If yes, replace the oldest one with the new record
If no, add a new record
Let’s say the records have the fields: