PDA

View Full Version : Does this query do what I want?


NancyJ
02-09-2008, 06:34 PM
I want to delete any contests that haven't been run in the last 90 days.
I have a table of contests and a table of contest times

This is the query


SELECT * FROM contests c
where active = 0
having
(select max(datetime) from contest_times
where c.id = contest_times.id) < date_sub(CURDATE(), interval 90 day)


Bonus question - how do I convert that into a delete

shyam
02-10-2008, 12:47 AM
delete from contests c where c.active=0 and c.id in
( select id from
( select ct.id, max(ct.datetime) from contest_times ct group by ct.id
having max(ct.datetime) < date_sum(curdate(), interval 90 day)
)
)