title: Getting Max date from the given two dates in mysql
body: <p>I have a table with below structure and data.</p>
  
  <pre><code>id ean           Control_date qty
  1  4046228081410 26.05.2017   568
  2  4046228081410 05.06.2017   900
  </code></pre>
  
  <p>My expected result would be like below </p>
  
  <pre><code>2  4046228081410 05.06.2017   1468
  </code></pre>
  
  <p>To acheive this i am using the below query </p>
  
  <pre><code> SELECT EAN,Control_date,SUM(Qty) AS Qty FROM mytable WHERE
  (STR_TO_DATE(`Control_date`,'%d.%m.%Y') &lt;= STR_TO_DATE('03.06.2017','%d.%m.%Y') 
  OR 
  STR_TO_DATE(`Control_date`, '%d.%m.%Y') &lt;= DATE_ADD(STR_TO_DATE('03.06.2017', '%d.%m.%Y'), INTERVAL 7 DAY))
  AND ean = 4046228081410  
  </code></pre>
  
  <p>Here i need to sum up the qty where control date&lt; today date and control date > today date and should be less than todaydate + 7 days . Here 2nd control date is 05.06.2017 and greater than today date and less than (03.05.2017 +7 days)
  But always i am getting where contorl date is less than today date.</p>
  
  <pre><code>1  4046228081410 26.05.2017   1468
  </code></pre>
  
  <p>But i need data with control date <strong>05.06.2017.</strong>
  Any help would be greatly appreciated.</p>