Reputation: 7201
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
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
Reputation: 36513
SELECT ColumnSurname FROM MyTable GROUP BY ColumnSurname HAVING count(*)>1
Upvotes: 1
Reputation: 2702
SELECT ColumnSurname FROM MyTable GROUP BY ColumnSurname HAVING COUNT(ColumnSurname) > 1 ?
Upvotes: 5