-5

Because of poor data entry policies, there are a lot of duplicate phone numbers to the same customers. I need to write a query that will list all customers with the same phone number.

Thanks for your help.

Dafna
  • 1
  • 2

1 Answers1

4
;WITH dupes AS
(
  SELECT Phone_Number
  FROM dbo.Customer_Table
  GROUP BY Phone_Number
  HAVING COUNT(*) > 1
)
SELECT c.Customer_Name, dupes.Phone_Number
  FROM dupes 
  INNER JOIN dbo.Customer_Table AS c
  ON dupes.Phone_Number = c.Phone_Number;
Aaron Bertrand
  • 272,866
  • 37
  • 466
  • 490