title: MySQL select older rows than x days, group by and order by and limit
body: <p>I made a really ugly SQL table long time ago. But now I need to use the data from it. 
  The table looks like this:
  <code>id =&gt; 1</code>
  <code>video_id =&gt; gds1513sfsd51</code>
  <code>user_ip =&gt; 244.154.16..</code>
  <code>datum =&gt; 2011-01-11 10:10:10</code>
  <code>referer =&gt; http://something.com</code>
  <code>user_id =&gt; 1</code></p>
  
  <p>I whould like to get those rows are older than 30 days, but I would like to <code>group</code> them by <code>video_id</code> and <code>order</code> by <code>id</code> desc</p>
  
  <p>So, these are the rows</p>
  
  <pre><code>id          video_id            ip               datum                user_id
  527557  152547560451c58ca74e2e8 162.217.250.110 2013-11-18 21:53:10     1
  527556  152547560451c58ca74e2e8 162.217.250.110 2013-11-18 21:53:07     1
  527369  152547560451c58ca74e2e8 162.217.250.110 2013-11-18 21:37:03     1
  515760  152547560451c58ca74e2e8 108.178.60.2    2013-11-15 02:33:45     1
  515763  252547560451c58ca74e2e9 108.178.60.2    2013-10-15 02:33:45     2
  515764  252547560451c58ca74e2e9 108.178.60.5    2013-10-14 02:33:45     2
  </code></pre>
  
  <p>I would like to get only the row with id <code>515763</code> , because that is older than one month and there is no newer with that <code>video_id</code> . </p>
  
  <p>I have tried to make something like this one:</p>
  
  <pre><code>    $format = 'Y-m-j G:i:s'; 
      $date = date ( $format ); 
      // - 1 month from today 
     $datum = date ( $format, strtotime ( '-1 month' . $date ) );
  
  $query = 'SELECT * FROM video_megtekintes WHERE datum &lt;= "'.$datum.'" group by video_id order by id desc LIMIT 100';
  
  print($query.'&lt;hr&gt;');
  $le = mysql_query($query);
  
  while($i = mysql_fetch_assoc($le)){
  print($i["video_id"].' - '.$i["datum"].'');
  $ok = mysql_fetch_assoc(mysql_query('SELECT * FROM video_megtekintes WHERE video_id="'.$i["video_id"].'" ORDER BY id DESC LIMIT 1'));
  print(' - &lt;b&gt;'.$ok["datum"].'&lt;/b&gt;&lt;br&gt;');
  //
  </code></pre>
  
  <p>But the output is something like this now:
  (video_id | datum | and the latest rows' datum with the same video_id)</p>
  
  <pre><code>video_id                   datum               from_a_new_query_it_shows_me_there_is_newer
  1000657739521a10654224f - 2013-08-25 19:15:26 - 2013-12-05 05:56:20
  100155265051bde3b822f84 - 2013-06-18 20:59:31 - 2013-11-04 23:48:06
  10024035651dc34f02b5d4 - 2013-07-14 10:10:52 - 2013-10-04 19:57:06
  </code></pre>
  
  <p>I don't want to see the first row, because it has two dates.. That video_id is with a newer date than one month. Can you help me a bit, please?</p>
  
  <p>This is the query:</p>
  
  <pre><code>$query = 'SELECT * FROM video_megtekintes WHERE datum &lt;= "'.$datum.'" group by video_id order by id desc LIMIT 100';
  </code></pre>