日期:2014-05-16  浏览次数:20668 次

mysql比较恶心的一个delete in操作
mysql中
delete from sns_hits where id not in (1,2,3)
是没有问题的
delete from sns_hits where id not in (select id from another_table)
也是麽有问题的

但是
delete from sns_hits where id not in (select id from sns_hits) 
就TMD有问题了

解决棒法是创建临时表
CREATE TEMPORARY TABLE tmp_sns_hits (
  `id` BIGINT(20) 
)


太丫恶心了
1 楼 不是流氓 2009-07-19  
delete from sns_hits where id not in (select id from sns_hits)   

有这样的需求
2 楼 xly_971223 2009-07-19  
不是流氓 写道
delete from sns_hits where id not in (select id from sns_hits)   

有这样的需求

后面的select 加个where怎么养?
3 楼 kjj 2009-07-20  
delete from sns_hits where id not in (select id from sns_hits)  


好神奇哦,作者用这个语句来干什么啊
从这个表里删除不在这个表里的元素?
4 楼 仅此而已 2012-08-21  
起个别名就好!

DELETE   FROM t_tag
WHERE id NOT IN (SELECT * FROM (SELECT MAX(t .id) AS id FROM t_tag t GROUP BY tagname)t)