21.5. The LIST() Aggregate Function

The LIST([DISTINCT] <string expression>) is part of Sybase’s SQL Anywhere (formerly WATCOM SQL). It is the only aggregate function to work on character strings. It takes a column of strings, removes the NULLs and merges them into a single result string with commas between each of the original strings. The DISTINCT option removes duplicates as well as NULLs before concatenating the strings. This function is a generalized version of concatenation, just as SUM() is a generalized version of addition.

MySQL 4.1 extended this function into the GROUP_CONCAT() function, which does the same thing but adds options for ORDER BY and SEPARATOR.

This is handy when you use SQL to write SQL queries. As one simple example, ...

Get Joe Celko's SQL for Smarties, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.