I have a table for appointments containing dates and Pupil IDs which I am trying to get to automatically duplicate on a weekly basis. I want to run a query which detects if each appointment has a copy of itself a week ahead, so original data was:
PupilID Date
1 10th May
2 16th May
After the query,
PupilID Date
1 10th May
2 16th May
1 17th May
2 23rd May
I am trying to use the following with no luck. Suggestions would be much appreciated. I have code doing the job already, but it is getting really slow.
INSERT timetable (pupil_id,date) SELECT timetable.pupil_id AS pupil_id2,DATE_ADD(timetable.date,INTERVAL 14 DAY) AS date2 FROM timetable WHERE NOT EXISTS pupil_id2=timetable.pupil_id AND date2=timetable.date;
Would it be sufficient to check whether there was a future appointment at all?
Give this a shot:
You could change the last clause to specifically check for the 14 days ahead:
I recommend the first query though.