title: How to query earliest date from several possibly blank date fields?
body: <p>Given the following table:</p>
  
  <pre><code>+----+----------+-----------+----------+
  | ID |  date1   |   date2   |  date3   |
  +----+----------+-----------+----------+
  |  1 | 3/2/2013 | 5/6/2013  |          |
  |  2 |          | 12/1/2011 | 6/5/2010 |
  |  3 | 1/1/1936 | 1/5/1936  | 1/9/1945 |
  |  4 | 2/1/2014 |           |          |
  +----+----------+-----------+----------+
  </code></pre>
  
  <p>I want a query that returns the earliest date in each row.  At least one of the date columns will be populated.</p>
  
  <p>I've tried:</p>
  
  <pre><code>SELECT id, 
  iif(date1&lt;date2 and date1&lt;date3,
      date1,
      iif(date2&lt;date1 and date2&lt;date3,
          date2,
          date3)) as dateEarliest
  FROM tbl;
  </code></pre>
  
  <p>But it seems that this only returns the correct result if <code>date3</code> is the earliest; otherwise  it returns a blank.</p>