Suppose I have a SQL table \"Celebrities\" with two columns: \"fname\" and \"lname\":
fname | lname ---------+------- Bill | Clinton Bill |
select fname, lname from ( select fname, lname, count(*) over(partition by lname) as lcount from Celebrities ) as S where lcount > 1
Tested in SQL Server 2008. Might work in other DBMS that support count(*) over(...)
count(*) over(...)