title: MySql SELECT, check if record has different value in Status then use one
body: <p>I have this table of orders and statuses:</p>
  
  <pre><code>id   |   date          |   status
  123    2015-12-01           order
  123    2015-12-20           refund
  234    2015-12-21           order
  456    2015-12-22           order
  456    2015-12-22           refund
  </code></pre>
  
  <p>Now I'd like to get results on 'status' column that whenever the ID also has a status of 'refund' then use this value instead of value 'order'. </p>
  
  <p>As follows:  </p>
  
  <pre><code>id   |   date        |   status    | refund_date
  123    2015-12-01         refund      2015-12-20
  234    2015-12-21         order
  456    2015-12-22         refund      2015-12-22
  </code></pre>
  
  <p>I have this query that retrieves the refund_date but I'm unsure how to get the status for refund orders. Additionally the table has like 500k records so performance is a key.</p>
  
  <pre><code>select 
      id,
      date,
      status,
      case when count(id)&gt;1 then max(date) else min(date) end as refund_date
  from orders
  group by id 
  </code></pre>
  
  <p>Much appreciated.</p>