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 管先飛 閱讀(2558) 評論(0)  編輯  收藏 所屬分類: Database
          主站蜘蛛池模板: 辰溪县| 尚义县| 高要市| 南华县| 田东县| 大城县| 商城县| 澎湖县| 宾阳县| 襄垣县| 苍南县| 龙岩市| 雷波县| 宾川县| 体育| 开鲁县| 萝北县| 盐边县| 中江县| 安龙县| 阿瓦提县| 尉犁县| 乌苏市| 纳雍县| 安岳县| 乐陵市| 射阳县| 棋牌| 弥渡县| 永修县| 偏关县| 苗栗县| 江安县| 乌兰浩特市| 保靖县| 昌都县| 武宁县| 苗栗市| 武乡县| 泰州市| 会昌县|