title: Tweaking query to account for an if statement?
body: <p>I have a query like below, where based on if the <strong><em>original_time</em></strong> column is less than or earlier then <strong><em>start_time</em></strong> then it gives me the first time as time column that is being subtracted from the original time column in the date diff calculated field as below. </p>
  
  <p>The <strong><em>table m</em></strong> has two time columns, also a <strong><em>second_time</em></strong> column, is there a way where I can tweak the query below to say based on if the <strong><em>t.original_time</em></strong> column is less than or earlier than the <em>start_time</em> column, then the <strong><em>m.first_time</em></strong> column is being used in the calculated field, and if the <strong><em>t.original_time</em></strong> column is > or later than the <strong><em>m.start_time</em></strong> field, then it will use the m.second_time column in the calculated field? Instead of running this query twice?</p>
  
  <pre><code>SELECT t.id,
         t.time,
         m.first_time,
         date_diff('minute',m.first_time, t.original_time) AS Calculation
  FROM table t
  JOIN table m ON t.id = m.id
  WHERE t.original_time &lt; m.start_time
  </code></pre>
  
  <p>Second query I am running is:</p>
  
  <pre><code>SELECT t.id,
             t.time,
             m.second_time,
             date_diff('minute',m.second_time, t.original_time) AS Calculation
      FROM table t
      JOIN table m ON t.id = m.id
      WHERE t.original_time &gt; m.start_time
  </code></pre>
  
  <p>Basically instead of running these 2 queries just tweak it to account for both?</p>
  
  <p>Thanks for the time!</p>