title: MYSQL Statement Issues - INNER JOIN, LEFT JOIN WITH GROUP BY and MAX
body: <p>I can't for the life of me get this statement to work.</p>
  
  <pre><code>SELECT max(pm.timestamp), pm.id, pm.p_media_user_id, pm.p_media_type, 
  pm.p_media_file, pm.wall_post, pm.p_media_location,pm.p_media_location_name, 
  pm.p_media_category, pa.p_source_alert_id, pa.post_id, pa.p_target_alert_id, 
  pu.fb_id, pu.username, pu.city, pu.sex, pu.main_image 
  
  FROM p_media as pm 
  
  INNER JOIN p_users as pu ON pm.p_media_user_id = pu.fb_id 
  
  LEFT JOIN p_alerts as pa ON pm.id = pa.post_id AND pa.p_source_alert_id ='3849084' 
  
  group by pm.p_media_user_id;
  </code></pre>
  
  <p>The only thing that I am having issues with is the max(pm.timestamp), after the grouping I would expect it to show the NEWEST rows in the p_media table, but to the contrary it's doing the exact opposite and showing the oldest rows. So, I need the newest rows from the p_media table grouped by the user id which Join the p_users table.</p>
  
  <p>Thanks in advance, if anyone helps.</p>