title: ORDER by rating ASC not working in mysql
body: <p>Please take a look at this <strong><a href="http://sqlfiddle.com/#!2/35c36/11" rel="nofollow noreferrer">sqlfiddle</a></strong></p>
  
  <p>I'm working on a product review page where several approved reviews will be shown as well as approved responses to each of them. In the <code>TYPE</code> field, <code>0</code> means it's a review where <code>1</code> means it's a reply to one of the reviews. The repliers aren't allowed to rate the product, so it's NULL in the <code>rating</code> field. <code>ID_GROUP</code> represents which reviews the replies belongs to.</p>
  
  <p>I got the following statement from user John Ruddell in this <a href="https://stackoverflow.com/questions/24936690/two-limit-clauses-in-one-statement">thread</a> </p>
  
  <pre><code>SELECT pr.*, 
  IF( @A = t.id_group, 
     IF(pr.type = 0, 1, 
        IF(@B = 5, @B := 1, @B := @B +1) ), @B ) 
  AS group_col, @A := t.id_group 
  FROM ( SELECT DISTINCT id, id_group 
        FROM `product_review` 
        WHERE type ='0' 
        AND approved &lt;&gt; '0' 
        GROUP BY id_group 
        ORDER BY rating ASC // &lt;-- This doesn't work
        LIMIT 0, 5 ) t 
  JOIN `product_review` pr 
  ON pr.id_group=t.id_group 
  CROSS JOIN (SELECT @A := '', @B := 1) AS temp 
  WHERE approved &lt;&gt; '0'
  GROUP BY group_col, id_group 
  ORDER BY id_group,time ASC
  </code></pre>
  
  <p>It's working fine. However I can't yield the following result by adding an additional <code>ORDER BY rating ASC</code> at line 11:</p>
  
  <pre><code>ID  USERNAME    ID_GROUP    TYPE    RATING  APPROVED    TIME    GROUP_COL
  5   Tommy          5         0        2        1    1406937041     2    
  9   Sally          5         1      (null)     1    1407871782     3    
  3   May            3         0        3        1    1406237410     2    
  7   Sam            3         1      (null)     1    1406999453     3    
  1   Tom            1         0        5        1    1406232341     1    
  2   Peter          1         1      (null)     1    1406237052     2
  </code></pre>
  
  <p>Can anyone show me how to get this output?</p>