Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Querying for duplicate names
Message
 
 
À
07/09/2014 00:29:19
Mike Cole
Yellow Lab Technologies
Stanley, Iowa, États-Unis
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Autre
Versions des environnements
SQL Server:
SQL Server 2014
Application:
Web
Divers
Thread ID:
01607128
Message ID:
01607144
Vues:
49
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
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform