Skip to content
Advertisement

How to Sort this MySQL Query

I am trying to insert the ORDER BY in this query to sort the Total column:

With the following result:

Here’s what I have tried so far but no luck:

Advertisement

Answer

I think you want:

Rationale: the ORDER BY clause should go after all UNION ALL subqueries – so it needs to be outside of the GROUP_CONCAT(), in an outer CONCAT().

Also please note that you don’t need CONCAT() within GROUP_CONCAT(): MySQL does that by default already.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement