Keep in mind when using the group by and order by that MySQL is the ONLY database that allows for columns to be used in the group by and/or order by piece that are not part of the select statement.
So for example: select column1 from table group by column2 order by column3
That will not fly in other databases like Postgres, Oracle, MSSQL, etc. You would have to do the following in those databases
select column1, column2, column3 from table group by column2 order by column3
Just some info in case you ever migrate your current code to another database or start working in another database and try to reuse code.