title: How can I get last inserted values for a user?
body: <p>I have this MYSQL table...</p>
  
  <pre><code>+----+---------+-----------+---------------+------------+---------------------+
  | id | user    | val1      | val2          | val3       | last_modified_date  |
  +----+---------+-----------+---------------+------------+---------------------+
  |  1 |    0001 |         1 |             1 |          1 | 2014-03-31 16:53:29 |
  |  2 |    0100 |         1 |             1 |          1 | 2014-04-01 10:32:50 |
  |  3 |    0200 |         1 |             0 |          0 | 2014-04-01 10:34:13 |
  |  4 |    0200 |         1 |             1 |          1 | 2014-04-01 14:43:47 |
  +----+---------+-----------+---------------+------------+---------------------+
  </code></pre>
  
  <p>What I'm trying to achieve is getting all the last (in order of time) set of values created for the users.</p>
  
  <p>In the example given we insert 0 for user 0200 but after 4 hours we insert 1. I want to be able to get the last value inserted (1).</p>
  
  <p>I have this query:</p>
  
  <pre><code>select * 
  from table 
  where val3 = 1 
  group by user 
  order by last_modified_date desc;
  </code></pre>
  
  <p>And a more generic one</p>
  
  <pre><code>select * from table group by user order by last_modified_date desc;
  </code></pre>
  
  <p>These queries seems to be working fine for the example table. Are they correct for every case? How can I tell "select all the users that have val3 = 1 as their last inserted value"?</p>