title: How to compare two tables using a like match based on multiple columns in SQL Server or R
body: <p>I have been trying to look for a solution to this for days now. I have two tables with the following fields</p>
  
  <ul>
  <li><em>Table 1</em> - <code>OEM_NAME, OEM_MODEL, SUPPLIER - contains 413000 records</code></li>
  <li><em>Table 2</em> - <code>OEM_Name, Model, Supplier_Name, SUPPLIER_MODEL - contains 208000 records</code></li>
  </ul>
  
  <p>The problem is that the field values do not match exactly and I am trying to implement a like comparison between the two tables that use multiple fields in the join condition. However, this query is taking forever to execute. Is there a better way of implementing a like comparison between two tables with multiple fields. I am familiar with SQL Server and R so I would really appreciate any solution/guidance that would work in one of these platforms. </p>
  
  <pre><code>SELECT COUNT(*)
    FROM Catalog_Table as CAT
    INNER JOIN POPULATION_TABLE AS POP
    ON POP.OEM_NAME LIKE CONCAT(CAT.OEM_NAME,'%') 
     AND POP.OEM_MODEL LIKE CONCAT(CAT.MODEL,'%') 
     AND POP.SUPPLIER LIKE CONCAT(CAT.SUPPLIER_NAME,'%') 
  </code></pre>
  
  <p>Update:</p>
  
  <p>Sample Data:</p>
  
  <p><a href="https://i.stack.imgur.com/gMnqc.png" rel="nofollow noreferrer">Sample Data</a></p>
  
  <p>I also tried another approach to solve this problem. I concatenated the input fields in both the tables to form a key and tried to use this single concatenated field to perform a match - both exact and Levenshtein distance (fuzzy match)</p>
  
  <p>Desired Result:</p>
  
  <p>The objective here is to perform a like match and then manually scan the matched records to see if the match makes sense. </p>