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?
CodePudding user response:
Try
SELECT *
FROM A
LEFT JOIN B ON A.company_name LIKE CONCAT('%', B.company_name, '%');
CodePudding user response:
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);