[英]Joining Tables based off LIKE words
I have two tables that list out companies.我有两张列出公司的表格。 There are 1000s of companies in table a but only about 150 in table b.
表 a 中有 1000 家公司,但表 b 中只有大约 150 家。 Unfortunately, the companies are written a bit differently in each of the tables.
不幸的是,每个表格中的公司写法都有些不同。 For example, table a might have ' Walmart, INC.'
例如,表 a 可能包含“Walmart, INC.”。 while table b might just have 'Walmart'.
而表 b 可能只有“沃尔玛”。 Is there a way to join these two tables off the first word in the company name for each?
有没有办法将这两个表从公司名称的第一个单词中加入?
Try尝试
SELECT * FROM A LEFT JOIN B ON A.company_name LIKE CONCAT('%', B.company_name, '%'); SELECT * FROM A LEFT JOIN B ON A.company_name LIKE CONCAT('%', B.company_name, '%');
LEFT
and CHARINDEX
will do the job, if each company is separated with the following character ',' LEFT
和CHARINDEX
将完成这项工作,如果每个公司用以下字符分隔,'
SELECT *
FROM A
LEFT JOIN B ON B.company_name = LEFT(A.company_name, CHARINDEX(',', A.company_name) - 1);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.