Così?

codice:
SELECT MAX(id), ordine, riga FROM `msg` WHERE ordine=1 GROUP BY riga