I have a query that updates the db using EVENT SCHEDULER. Its supposed to update data once a day. My issue is that I can't get it to update if the record exists unless I create UNIQUE INDEX which I can't do since the domain repeats for each month.
INSERT INTO f_s.s_d_s_tab(month,count_per_month,updated)
SELECT * FROM
(
SELECT
DATE_FORMAT(`FE`,'%m') AS Month, COUNT(FE) AS FirstCount, domain
FROM rets
GROUP BY DATE_FORMAT(`FE`,'%m'), domain
ORDER BY domain, Month ASC
) a
ON DUPLICATE KEY UPDATE count_per_month = a.FirstCount, updated = NOW();
records show like so
Domain Month coun_per_month
dom1 01 50
dom1 02 90
dom1 03 34
dom2 01 12
dom2 02 99
dom2 03 80
etc....
what can I do to make it insert new domains but update old ones.