正文

如何删除数据表格中的重复记录2008-02-22 12:08:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/daweizhao/32859.html

分享到:

有思路,但是效率太差,要不断的遍历整个数据库表格,在SQL中有没有简单的方法呢,正在寻找中。。。。。。

select id from answer_new
where (property1,property2,property3) IN
(select property1,property2,property3 from answer_new
group by property1,property2,property3
having count(*) > 1)                                  不完全正确

其中,select property1,property2,property3 from answer_new
group by property1,property2,property3
having count(*) > 1 查询出数据库中property1,property2,property3相同的数据a1 b2 c1

但是IN的用法是不对的,会提示出现‘第 2 行: ',' 附近有语法错误’或‘当没有用 EXISTS 引入子查询时,在选择列表中只能指定一个表达式。’的错误提示信息,原因是IN时, in 里面的查询语句应该只写一个字段

难道只能一个property一个property的去相等么?有没有简便的方法?

目前想到的方法是这个,可也太复杂了吧:

select ID from answer_new
where property1 IN
(select property1 from answer_new
group by property1,property2,property3
having count(*) > 1)
AND
(property3) IN
(select property3 from answer_new
group by property1,property2,property3
having count(*) > 1)
AND
(property2) IN
(select property2 from answer_new
group by property1,property2,property3
having count(*) > 1)

如果在程序中实现用真实数据中,要用几个AND才可以?!!

如果多个IN的可以就万事大吉了,还是先将a1 b2 c1的查询结果保存下来,再一个property一个property的去相等吧。。。。。。

阅读(3128) | 评论(0)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

暂无评论
您需要登录后才能评论,请 登录 或者 注册