title: fetching only latest data in mysql for each record
body: <p>I have a table schema like this</p>
  
  <ol>
  <li>User(int)</li>
  <li>created(datetime)</li>
  <li>metadata</li>
  </ol>
  
  <p>and there are multiple entries in the table for a single user id. </p>
  
  <p>i want to fetch only those data for every user for which created is maximum or latest.</p>
  
  <p>i tried many query but its not working. they are fetching oldest data.
  i tried these queries </p>
  
  <pre><code>  select user, metadata, max(created) 
    from event_visitor 
    group by user 
    order by max(created)
  </code></pre>
  
  <p>and</p>
  
  <pre><code>  SELECT ev1.user, ev1.metadata, ev1.created 
    from event_visitor ev1 
         inner join event_visitor ev2 
         on ev1.user=ev2.user 
    where ev1.created &gt; ev2.created 
    group by user
  </code></pre>
  
  <p>please help</p>