title: JOIN tables based on 6 or 7 digits key in 1st table with 7 digits key in second table by using CASE and MAX function
body: <p><strong>Table 1:</strong></p>
  
  <pre><code>Id1 Data1
  123123  David
  123124  Jan
  1231344 Juro
  1234126 Marco
  </code></pre>
  
  <p><strong>Table 2:</strong></p>
  
  <pre><code>Id2 Data2
  1231230 Info 1
  1231231 Info 2
  1231232 Info 3
  1231240 Info 4
  1231241 Info 5
  1231242 Info 6
  </code></pre>
  
  <p>Each id from Table 1 can have 1 or more matches in Table 2 based on first 6 digits. 
  For example 123123 from Table 1 matches  1231230, 1231231 and 1231232 in Table 2. 
  I'm trying to create join to match maximum id2 from Table 2 based on id1 from Table 1. </p>