title: MySQL: Group By Min & Max Value
body: <p>I have below query        </p>
  
  <blockquote>
    <p>SELECT cped.entity_id, cped.value FROM sales_order so LEFT JOIN
    sales_order_item soi ON so.entity_id = soi.order_id LEFT JOIN
    catalog_product_entity_datetime cped ON soi.product_id =
    cped.entity_id AND cped.attribute_id IN (153,154)</p>
  </blockquote>
  
  <p>Result:</p>
  
  <pre><code>entity_id   value   
  2340        2017-03-01 00:00:00
  2340        2017-03-16 00:00:00
  2312        2017-03-01 00:00:00
  2312        2017-03-31 00:00:00
  </code></pre>
  
  <p>Need output: </p>
  
  <pre><code>entity_id   value   
  2340        2017-03-01 00:00:00 // Start Date
  2340        2017-03-16 00:00:00 // End Date
  </code></pre>
  
  <p>So entity_id wise we have to compare min &amp; max value with current date. It both are less than current date then result should display. I tried using having but not working properly.</p>