简体   繁体   中英

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. Unfortunately, the companies are written a bit differently in each of the tables. For example, table a might have ' Walmart, INC.' while table b might just have 'Walmart'. 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, '%');

LEFT and CHARINDEX will do the job, if each company is separated with the following character ','

SELECT *
FROM A
LEFT JOIN B ON B.company_name = LEFT(A.company_name, CHARINDEX(',', A.company_name) - 1);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM