我想要獲取具有相同電話號碼的客戶列表,因爲有相同客戶的實例創建了兩次或三次,名稱略有不同。加入SQL表並刪除重複
查詢下面已經幾乎是預期的行爲:
SELECT C1.CUSTOMER_NAME, C2.CUSTOMER_NAME, C1.PHONE_NUMBER
FROM CUSTOMER C1
JOIN CUSTOMER C2
ON C1.PHONE_NUMBER = C2.PHONE_NUMBER
WHERE C1.CUSTOMER_NAME != C2.CUSTOMER_NAME
AND C1.PHONE_NUMBER != ''
ORDER BY C1.CUSTOMER_NAME
,但我得到repetions這樣的:
Customer A - Customer B
Customer A - Customer C
Customer B - Customer A
Customer B - Customer C
Customer C - Customer A
Customer C - Customer B
當所有我想要得到的是前兩行,這是足以覆蓋所有的情況。
在此先感謝您的幫助。
明確你想要它的位混淆寫希望的結果,並提供你的結果集。 – 2015-02-10 16:43:45