How to sort a group in the mysql query?

1

I'm trying to sort a query in the database by grouping the information, however this is showing the first one registered in the database, but I want the last.

SELECT *
FROM base_rating AS B
JOIN historico_rating AS H ON B.id = H.id_base_rating
JOIN escala_rating AS E ON E.id = H.id_rating_atual
WHERE H.titulo!=''
  AND E.agencia!=''
GROUP BY B.id_emissao
    
asked by anonymous 28.08.2017 / 20:20

1 answer

1

Although I find that your SQL does not run, for your needs, it does B.id_emissao desc .

Full SQL

select 
  * 
from
  base_rating as B 
  JOIN historico_rating as H on B.id = H.id_base_rating 
  JOIN escala_rating as E on E.id = H.id_rating_atual 
where 
  H.titulo!='' and 
  E.agencia!='' 
group by 
  B.id_emissao desc

Edited

If you want only 1 record as indicated by other users, add limit 1

    
28.08.2017 / 20:28