2012-03-02 1 views

답변

9

당신은 테이블 구조에 대한 자세한 내용을 게시 할 수 있으며 일부 중복되지만 두 개의 열로 것을 무엇을 의미합니까?

어쨌든, 당신은 GROUP BY, COUNT을 조사하고 있습니다 HAVING

SELECT `duped_field1`, `duped_field2`, COUNT(*) `tot` 
FROM `table` 
GROUP BY `duped_field1`, `duped_field2` 
HAVING `tot` > 1 
3

중복을 찾기위한 일반적인 원칙은 그냥 중복 열을 알고 싶다면 바로 group byhaving 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

또는 단순히'*'...'* 선택 추가, COUNT (*) tot' – Fabrizio

관련 문제