I have 2 identical tables DATES and DATES_ARCHIVED
I want to select in the DATES table all the rows that have dates that are older than current date -88 days, then insert those rows into the DATES_ARCHIVED.
I have created a CASE for this.
Then after the insertion I want to delete those same rows from the original DATES table.
I am certain I got this to work before, but it's not working anymore it keeps giving error:
Error Code: 1136. Column count doesn't match value count at row 1
all the tables have the same amount of columns and I also removed the 2 triggers I had on the tables but the same error occurs.
I am pretty sure it's because of the case where it ends AS MostRecentDate, I think this is adding a new column.
Also if I remove all the code below the first: from dates, I get the same error
Here is the code:
INSERT INTO dates_archived
(term, course_no, date1_end, date2_end, date3_end, date4_end)
SELECT
term, course_no, date1_end, date2_end, date3_end, date4_end,
CASE WHEN date1_end > date2_end THEN date1_end
WHEN date2_end > date1_end THEN date2_end
WHEN date3_end > date1_end THEN date3_end
WHEN date4_end > date1_end THEN date4_end
WHEN date1_end > date3_end THEN date1_end
WHEN date2_end > date3_end THEN date2_end
WHEN date3_end > date2_end THEN date3_end
WHEN date4_end > date2_end THEN date4_end
WHEN date1_end > date4_end THEN date1_end
WHEN date2_end > date4_end THEN date2_end
WHEN date3_end > date4_end THEN date3_end
WHEN date4_end > date3_end THEN date4_end
ELSE 0
END AS MostRecentDate
FROM dates
HAVING (MostRecentDate <= (SELECT CURDATE() - INTERVAL 88 DAY));
FROM dates
WHERE (date1_end OR date2_end OR date3_end OR date4_end = MostRecentDate);
DELETE FROM dates
WHERE (date1_end OR date2_end OR date3_end OR date4_end = MostRecentDate);
Thanks in advance, Chris