首页 > 数据库技术 > 详细

sql删除语句的写法

时间:2015-03-02 02:00:59      阅读:309      评论:0      收藏:0      [点我收藏+]
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
)

sql删除语句的写法

原文:http://www.blogjava.net/17learning/archive/2015/03/01/423118.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!