title: Get most recent MySQL transaction only
body: <p>I'm trying to export a set of user information from one WordPress database to import into another database.  However I'm having trouble figuring out how to only export the most recent membership transaction for a user.  The following query exports all transactions for each user, but I only want the transaction with the most recent "t.expires_at" value.  I've tried various sub-queries etc based on other StackOverflow threads but can't quite figure it out.</p>
  
  <pre><code>SELECT DISTINCT
      u.user_login AS user_login, 
      u.user_email AS user_email, 
      u.user_registered AS user_registered, 
      f.meta_value AS first_name, 
      l.meta_value AS last_name,
      t.expires_at AS membership_enddate
  FROM 
      wp_acfzia_users AS u
  LEFT JOIN 
      wp_acfzia_usermeta AS f
      ON u.ID = f.user_id AND f.meta_key = 'first_name'
  LEFT JOIN 
      wp_acfzia_usermeta AS l
      ON u.ID = l.user_id AND l.meta_key = 'last_name'
  LEFT JOIN
      wp_acfzia_mepr_transactions AS t
      ON u.ID = t.user_id
  </code></pre>