title: How to select the latest date between two entries in mysql
body: <p>I have this query and this returns two columns that are almost the same except for two columns it looks like this:</p>
  
  <p>Entry 1: LOTNUM = TAOM7U034N, OPCODE = 8385, DATEADDED = 2015-09-04 05:19:00, DATERELEASED = 2015-09-09 15:41:00</p>
  
  <p>Entry 2: LOTNUM = TAOM7U034N, OPCODE = 8385, DATEADDED = 2015-09-28 16:51:00, DATERELEASED = 2015-10-01 14:34:00</p>
  
  <pre><code>SELECT
      LOTNUM,
      OPCODE,
      DATERELEASED
  FROM
      HOURLY_FT_WIP.CACHE_IRAC_HOLD_LOTS AS i
  WHERE
      LOTNUM IN('TAOM7U034N')
  AND DATEADDED =(
      SELECT
          MAX(DATEADDED)
      FROM
          HOURLY_FT_WIP.CACHE_IRAC_HOLD_LOTS x
      WHERE
          x.LOTNUM = i.LOTNUM
      AND x.OPCODE = i.OPCODE
  )
  </code></pre>
  
  <p>This query is alright and returns the 2nd entry and that is what I needed. But this query takes 15 seconds.</p>
  
  <p>I tried to modified to this:</p>
  
  <pre><code>SELECT
      LOTNUM,
      OPCODE,
      DATERELEASED
  FROM
      HOURLY_FT_WIP.CACHE_IRAC_HOLD_LOTS AS i
  WHERE
      LOTNUM IN('TAOM7U034N')
  GROUP BY LOTNUM, OPCODE
  </code></pre>
  
  <p>This one is much faster like 0.05 seconds. However this returns the first entry which is the older date. I need the latest date which is the 2nd entry.</p>