【发布时间】:2018-04-12 19:36:51
【问题描述】:
我有两张这样的桌子。
Table1
FullName LastName FirstName
John Smith Smith John
Table2
LastName Firstname AKA
Smith Stein Johnny John the Bad Guy
我需要在table2 中从table1 中找到lastname 和firstname 的任何变体。但是,我无法加入这些表,因为名称可能不同,所以没有什么可以加入的。基本上,我正在尝试将我们的列表与公共列表进行比较,以查看是否有任何名称匹配。
我正在尝试这个:
Select *
from table1
where exists (select *
from table2
where charindex(table1.lastname, table2.lastname)>0
and charindex(table1.firstname,table2.firstname)>0)
我得到了返回值,但我也想查看 table2 中的值。
我需要查看 John Smith Returned 并显示 John Smith Stein 在另一张表中被标记。姓氏的这种变体也适用于名字。这就是为什么我不能加入任何 1 个特定列的原因。
对不起,如果这令人困惑。
【问题讨论】:
-
请用您的数据库标记您的问题。
-
您需要提供样本数据和期望的结果,这样其他人就有可能知道您正在尝试做什么。
-
它的 SQL 2008 R2。我正在尝试弄清楚如何上传表格。
标签: sql sql-server-2008-r2 compare