Etienne
Etienne

Reputation: 7201

Getting duplicate of items in a database column

Database Name = MyDB

Table Name = MyTable

Column Name = ColumnSurname

Using SQL Server 2005

I have multiple entries in ColumnSurname and some of them are spelled exactly the same. How can i return all the distinct values with the same ColumnSurname value. Meaning i want to return "Bond" if "Bond" comes up more than twice.

How would i do this in a SQL statement?

Upvotes: 0

Views: 69

Answers (3)

Alexey Sviridov
Alexey Sviridov

Reputation: 3510

select ColumnSurName, count(*) from MyTable group by ColumnSurName having count(*) >1

If you want to see how many duplicates you have

Upvotes: 1

culebrón
culebrón

Reputation: 36513

SELECT ColumnSurname FROM MyTable GROUP BY ColumnSurname HAVING count(*)>1

Upvotes: 1

Locksfree
Locksfree

Reputation: 2702

SELECT ColumnSurname FROM MyTable GROUP BY ColumnSurname HAVING COUNT(ColumnSurname) > 1 ?

Upvotes: 5

Related Questions