Is it possible to sort the values in a GROUP_CONCAT? There does not appear to be an ORDER BY clause and I tried nesting the sort but it did not seem to work. If not, are there any other ways to achieve this requirement? I found this post on StackOverflow, which suggests using an analytical function such as row number and sorting by that.
This syntax will work in the upcoming 7.0 release:
SELECT dept_id, GROUP_CONCAT (emp_id ORDER BY emp_id SEPARATOR', ') as "employees ids" from employee group by dept_id;
But ORDER BY in GROUP_CONCAT is not supported in 6.8. A possible workaround would be to write a UDF, say SORT_GROUP, to parse the result of GROUP_CONCAT and sort it in an array, e.g.
SELECT dept_id, SORT_GROUP(GROUP_CONCAT (emp_id SEPARATOR', ')) as "employees ids" from employee group by dept_id;
The SPLIT function (https://docs.memsql.com/sql-reference/v6.8/split/) would make it easier to write.