I'm a beginner to SQL and would like to write a script that deletes rows from 2 tables of a MySQL database.
I have events and attendees and like to delete all attendee and event data from events that are older than 90 days. So I need to find an array of event_ids of old events and then delete all attendees refering to any event_id in that array.
What's the best way to solve that? Here is my idea:
DELETE * FROM attendees WHERE event_id = ANY (SELECT id FROM events WHERE enddate <= DATE_ADD(CURDATE(), INTERVAL -90 DAY))
DELETE * FROM events WHERE enddate <= DATE_ADD(CURDATE(), INTERVAL -90 DAY)