2016-07-27 56 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