Skip to content

GroupConcat: missing "ORDER BY" features #1101

@roniemartinez

Description

@roniemartinez

Description

Currently, GroupConcat() only accepts "asc", "desc" and None for ordering parameter.

But GROUP_CONCAT supports more complex features in ORDER BY.

As an example, multiple columns and expressions:

GROUP_CONCAT(column1 ORDER BY column2, NATURAL_SORT_KEY(column3) SEPARATOR ', ') AS mycolumn

In the example above, the ordering can be done using "other" columns (column2 and column3) similar to a standard "ORDER BY". (We use the raw SQL above since GroupConcat() don't support this at the moment)

As shown in the MySQL docs:

GROUP_CONCAT([DISTINCT] expr [,expr ...]
             [ORDER BY {unsigned_integer | col_name | expr}
                 [ASC | DESC] [,col_name ...]]
             [SEPARATOR str_val])

and MariaDB docs even added LIMIT support:

GROUP_CONCAT([DISTINCT] expr [,expr ...]
             [ORDER BY {unsigned_integer | col_name | expr}
                 [ASC | DESC] [,col_name ...]]
             [SEPARATOR str_val]
             [LIMIT {[offset,] row_count | row_count OFFSET offset}])

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions