guanxf

我的博客:http://blog.sina.com.cn/17learning

  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  71 随笔 :: 1 文章 :: 41 评论 :: 0 Trackbacks
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
)
posted on 2015-03-01 22:52 管先飞 阅读(2547) 评论(0)  编辑  收藏 所属分类: Database

只有注册用户登录后才能发表评论。


网站导航: