title: Pulling data from a table using MAX and GROUP BY
body: <p>I'm trying to pull data out from a table. To simplify I have a table (time_entries ) has 3 colums user_name, entry_type and entry_datetime</p>
  
  <p>Here is a sample output</p>
  
  <pre><code>user_name| entry_type   | entry_datetime
   User1   |   Time In    | 28-JUL-13  16:40:40
   User1   |   Time Out   | 28-JUL-13  16:40:41
   User2   |   Time In    | 28-JUL-13  16:41:13
   User2   |   Time Out   | 28-JUL-13  16:41:15
   User3   |   Time In    | 28-JUL-13  16:42:32
  </code></pre>
  
  <p>What I'm trying to do here is to pull the result when the last time each User logged in</p>
  
  <p>MY QUERY</p>
  
  <pre><code>SELECT te.user_name, te.entry_type,  MAX(te.entry_datetime) AS date
  FROM time_entries AS te
  GROUP BY te.user_name 
  </code></pre>
  
  <p>this runs fine only with wrong results, here is the output below</p>
  
  <p>OUTPUT</p>
  
  <pre><code>user_name| entry_type | entry_datetime
  User1    | Time In    | 28-JUL-13 16:40:41
  User2    | Time In    | 28-JUL-13 16:41:15
  User3    | Time In    | 28-JUL-13 16:42:32
  </code></pre>
  
  <p>user_name and entry_datetime is correct but the entry_type are all Time In. User1 and User2 entry_type must be Time Out. </p>
  
  <p>Anyone knows a solution for this problem? </p>