Monday, July 20, 2009

selecting duplicate rows

Ever wondered how to select only rows that have some duplicate from a field? Well, here is one way that worked pretty well:
select duplicate_column from table_with_duplicates where
(
select count(a.duplicate_column) from table_with_duplicates a
where a.duplicate_column = table_with_duplicates.duplicate_column
) > 1
group by duplicate_column
Hope that helps someone.

No comments: