title: SQL: Select the minimum value from multiple columns with null values
body: <p>I have a table like this one    </p>
  
  <pre><code>ID   Col1   Col2   Col3
  --   ----   ----   ----
  1      7    NULL    12  
  2      2     46    NULL
  3     NULL  NULL   NULL
  4     245     1    792
  </code></pre>
  
  <p>I wanted  a query that yields the following result </p>
  
  <pre><code> ID   Col1   Col2   Col3  MIN
   --   ----   ----   ----  ---
    1     7    NULL    12    7
    2     2     46    NULL   2
    3    NULL  NULL   NULL  NULL
    4    245    1     792    1
  </code></pre>
  
  <p>I mean, I wanted a column containing the minimum values out of Col1, Col2, and Col 3 for each row ignoring NULL values. In a previous question (<a href="https://stackoverflow.com/questions/368351/whats-the-best-way-to-select-the-minimum-value-from-multiple-columns">What's the best way to select the minimum value from multiple columns?</a>) there is an answer for non NULL values. I need a query as efficient as possible for a huge table.</p>
  
  <pre><code>Select Id,
         Case When Col1 &lt; Col2 And Col1 &lt; Col3 Then Col1
              When Col2 &lt; Col1 And Col2 &lt; Col3 Then Col2 
              Else Col3
              End As MIN
  From   YourTableNameHere
  </code></pre>