title: MySql sort by highest value with inner join and subquery
body: <p>I have a query that has a sub query that returns a count of records from another table, I'm having trouble ordernar the largest number of this counter</p>
  
  <pre><code>SELECT respostas.id,
         respostas.cmm,
         respostas.topico,
         respostas.usuario,
         respostas.resposta,
         perfis.nome,
         perfis.sobrenome,
         respostas.datahora,
         (
             SELECT count(id) 
             FROM likes 
             WHERE respostas.id = resposta
         ) AS total
  FROM respostas
  INNER JOIN perfis ON respostas.usuario = perfis.id
  INNER JOIN likes ON respostas.topico = likes.topico
  WHERE respostas.cmm = 28
          AND respostas.topico = 38
  ORDER BY respostas.id ASC, total ASC
                  LIMIT 0,20`enter code here`
  </code></pre>
  
  <p>I want to sort by the total column and can not.
  Sorting by total does not work, only ordered by id</p>