Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Querying for duplicate names
Message
 
 
To
07/09/2014 00:29:19
Mike Cole
Yellow Lab Technologies
Stanley, Iowa, United States
General information
Forum:
Microsoft SQL Server
Category:
Other
Environment versions
SQL Server:
SQL Server 2014
Application:
Web
Miscellaneous
Thread ID:
01607128
Message ID:
01607144
Views:
50
This message has been marked as a message which has helped to the initial question of the thread.
Here is another way without a subquery:
;with cte as (select *, count(*) over (partition by LastName, FirstName) as cntDups
from Users)

select * from cte where cntDups > 1
>I have a list of people that I need to do a duplicate name check on and display the results along with the IDs. I was going to do a simple GROUP BY, but then I'd have to join back to the original table to get the ID. Is there something sexier? (11:30 on a Saturday night and I'm asking about sexy SQL queries....)
>
>
>SELECT
>	*
>FROM
>	Users users
>		INNER JOIN (
>					SELECT
>						FirstName, LastName
>					FROM
>						Users
>					GROUP BY
>						FirstName, LastName
>					HAVING
>						COUNT(*) > 1
>				   ) un ON (un.FirstName = users.FirstName AND un.LastName = users.LastName)
>
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform