title: SQL version of VLOOKUP
body: <p>I am new to SQL and if you have a spare moment, I was wondering whether anybody could help me replicate the Excel <code>Vlookup</code> function in SQL please?</p>
  
  <p>From some research, I am suspecting that it is one of the <code>join</code> functions that I require, however, I don't want to just select data that is contained in both tables -  I just want to lookup the value in 1 table against another. </p>
  
  <p>If the data is contained in the lookup table then return the value and if not, just return <code>NULL</code>.</p>
  
  <p>I have given a couple of example tables below to help illustrate my question.</p>
  
  <p><em>Please note that Products 'C' and 'D' are not in Table2 but they are still in the result table but with NULL value.</em></p>
  
  <p>Also I have a large number of unique products, so I am not looking for an answer which includes hard-coding, for example; <em><code>CASE WHEN [Product] = 'A' THEN...</code></em></p>
  
  <p><br><br>
  <strong>TABLE1</strong></p>
  
  <pre><code>Product    Quantity
  -------------------
  A          10
  B          41
  D          2
  C          5
  B          16
  A          19
  C          17
  A          21
  </code></pre>
  
  <p><strong>TABLE 2</strong></p>
  
  <pre><code>Product    Cost
  -----------------
  A          £31.45
  B          £97.23
  </code></pre>
  
  <p><br><br>
  <strong>RESULT TABLE</strong></p>
  
  <pre><code>Product   Quantity    Cost
  -----------------------------
  A         10          £31.45
  B         41          £97.23
  D         2           NULL
  C         5           NULL
  B         16          £97.23
  A         19          £31.45
  C         17          NULL
  A         21          £31.45
  </code></pre>