LISTAGG
Applies to: ✅ Data 360 SQL ✅ Tableau Hyper API
Concatenates the input values from a group into a single string, separated by a delimiter, in the order that you specify.
<value>: The string expression to concatenate.<separator>: A constant string placed between concatenated values. It must be a literal constant, not a computed expression. PassNULL::text(or'') to concatenate with no separator.
DISTINCT: Concatenates only distinct values. When you useDISTINCT, theORDER BYexpression (including its collation) must match<value>.WITHIN GROUP (ORDER BY <sort_expression> [, ...]): Orders the values before concatenation. Each sort key acceptsASC/DESCandNULLS FIRST/NULLS LAST.
A string containing the concatenated values.
Null handling:
NULLinputs are always skipped and contribute no separator.- A group whose values are all
NULLreturnsNULL. - Empty-string values are preserved and contribute separators (they aren’t treated as
NULL).
- The separator must be a constant. A computed separator such as
concat('-', '-')raises an error. LISTAGGrequires string arguments; binary (bytes) values aren’t supported.LISTAGGsupports theFILTERclause to restrict which rows feed the aggregate.- If no
ORDER BYis specified, the resulting string contains the entries in an implementation-defined, non-deterministic order. LISTAGGwithWITHIN GROUP (ORDER BY …)isn’t supported in combination withROLLUP,CUBE, orGROUPING SETS. UnorderedLISTAGG(noWITHIN GROUP) is supported with all of those.LISTAGGis equivalent toARRAY_TO_STRINGapplied toARRAY_AGG. UseARRAY_AGGwhen you need an array rather than a delimited string.
Concatenate x values in ascending order. The NULL input is skipped.
Returns a,b.
Build a comma-separated list of tags for each account.
Compute two independently filtered concatenations in a single query.