2016-07-27 42 views
-1

方案: 我們有一個名爲AddressTable的表。 在那裏,我們有4列: AddressID INT PK沒有允許空值 AddressLine1爲nvarchar(255) AddressLine2爲nvarchar(255) AddressLine3爲nvarchar(255)在SQL上使用Soundex進行模糊匹配 - 組合表

我應該使用什麼樣的邏輯,用比較的所有記錄模糊匹配相關函數返回可能重複的ID?

select AddressID, SOUNDEX(AddressLine1, AddressLine2, AddressLine3) from [AddressTable] 
+0

哪些DBMS您使用的? –

回答

0

做一個自我聯接:

select distinct t1.* 
from [AddressTable] t1 
join [AddressTable] t2 
    on t1.AddressID <> t2.AddressID and  
    SOUNDEX(t1.AddressLine1, t1.AddressLine2, t1.AddressLine3) = 
    SOUNDEX(t2.AddressLine1, t2.AddressLine2, t2.AddressLine3) 

或者,做一個EXISTS

select t1.* 
from [AddressTable] t1 
where exists (select * from [AddressTable] t2 
       where t1.AddressID <> t2.AddressID 
       and SOUNDEX(t1.AddressLine1, t1.AddressLine2, t1.AddressLine3) = 
        SOUNDEX(t2.AddressLine1, t2.AddressLine2, t2.AddressLine3)) 
+0

我想查看可能的重複項。我的意思是可能的重複。 英國南安普敦Wonston路1號郵編: 英國Hampshire Wnstn Roed 1 – Angie

+0

已更新。增加了替代查詢。 – jarlh