1、多表级联删除:
---DELETE---
DELETE from a_msg_push,a_announcement
using a_msg_push,a_announcement
where a_msg_push.announcement_id=a_announcement.id and a_announcement.Create_time<'2014-11-19 23:59:59';
2、子查询删除:
-----------delete--------
DELETE From t_repeat where t_repeat.id in(
SELECT tb.id from (
SELECT * from t_repeat t
where
1=1
and
(t.cid,t.uid ) in (select t1.cid,t1.uid from t_repeat t1 group by t1.cid,t1.uid having count(*) > 1)
and
t.id not in (select min(t2.id) from t_repeat t2 group by t2.cid,t2.uid having count(*)>1)
) as tb )
3、子表删除:
-----------delete--------
DELETE From t_repeat where t_repeat.id not in
(
SELECT tb.id from(
select a.id from t_repeat a where a.id =(
select max(b.id) from t_repeat b where a.cid=b.cid and a.uid=b.uid
)
)as tb
)