SQLite Forum

How to cancatenate all lines in table to a single string?
Login
The ORDER BY clause applies order to the OUTPUT of a projection (SELECT statement), not the INPUT to the projection.

SELECT group_concat(x) from x ORDER BY x;

makes absolutely no sense what so ever because the ORDER BY is applied AFTER the grouping is done to the OUTPUT rows (in this case only 1) and therefore does absolutely nothing.  It is ill-conceived from the get-go as a possible solution and any rational person knows it has absolutely zero possibility of working.

You want to sort the rows GOING INTO the aggregate, not COMING OUT OF the aggregate:

SELECT group_concat(x) from (select x from x order by x);

That has a CHANCE of working.  By happenstance it also does work.