title: MySql PDO - How to fetch "newest rows from group" when using GROUP BY, ORDER BY and INNER JOIN?
body: <blockquote>
  <pre><code>      products_table:             | p_id  | name  |
                                    | 1     | name1 |
                                    | 2     | name2 |
                                    | 3     | name3 |
  
  
        favourites_table:           | id    | p_id  | deleted   | group_id  |
                            fetch-&gt; | 1     | 1     | 0         | 11        |
                                    | 2     | 1     | 0         | 11        |
                            fetch-&gt; | 3     | 2     | 0         | 22        |
                                    | 4     | 2     | 0         | 22        |
                            fetch-&gt; | 5     | 3     | 0         | 33        |
                                    | 6     | 3     | 0         | 33        |
  </code></pre>
  </blockquote>
  
  <pre><code>    $sth = $db-&gt;prepare('   SELECT a.p_id, b.name
  
                              FROM favourites_table AS a
                              INNER JOIN products_table AS b
                              ON a.p_id = b.p_id
  
                              WHERE a.deleted=0
                              GROUP BY a.group_id
                              ORDER BY a.id ASC
                              LIMIT 0, 10;');
  
      $sth-&gt;execute();
  
  
      while(($query_data = $sth-&gt;fetch()) !== false) {
      echo $query_data['p_id'] . ':' . $query_data['name'] . '&lt;br&gt;';
      }
  </code></pre>
  
  <p>This query fetches rows 1, 3, 5 from 'favourites_table'.</p>
  
  <p>How to change it so it fetches "newest rows" (2, 4, 6) ?</p>
  
  <p>Do I have to change the whole query or am I missing something?</p>