mysql只选择从数据库重复记录
答
你能发表更多关于表结构的信息吗?你是指什么意思,有些是重复的,但只有两列?
无论如何,你可以看看到GROUP BY
,COUNT
和HAVING
SELECT `duped_field1`, `duped_field2`, COUNT(*) `tot`
FROM `table`
GROUP BY `duped_field1`, `duped_field2`
HAVING `tot` > 1
答
查找重复的一般原则是只使用group by
和having count(*) > 1
如果你只是想知道重复列值:
select col1, col2
from table
group by col1, col2
having count(*) > 1
但是如果您想要查看其中,两列是重复的所有领域:
select t.*
from @tbl t
where exists (select *
from @tbl d
where d.col1 = t.col1 and d.col2 = t.col2
group by d.col1
having COUNT(*) > 1)
+0
或只需添加'*''.. SELECT *, COUNT(*)tot' – Fabrizio 2014-09-07 18:15:15
http://stackoverflow.com/questions/854128/find-duplicate-records-in-mysql – 2012-03-02 22:06:32