%DLIST (SQL)
Synopsis
%DLIST([ALL | DISTINCT [BY(col-list)]]
string-expr
[%FOREACH(col-list)] [%AFTERHAVING])
Description
The %DLIST aggregate function returns an ObjectScript %List structure containing the values in the specified column as list elements.
A simple %DLIST (or %DLIST ALL) returns InterSystems IRIS list composed of all the non-NULL values for string-expr in the selected rows. Rows where string-expr is NULL are not included as elements in the list structure.
A %DLIST DISTINCT returns an InterSystems IRIS list composed of all the distinct (unique) non-NULL values for string-expr in the selected rows: %DLIST(DISTINCT col1). NULL is not included as an element in the %List structure. %DLIST(DISTINCT BY(col2) col1) returns a %List of elements including only those col1 field values in records where the col2 values are distinct (unique). Note however that the distinct col2 values may include a single NULL as a distinct value.
For further information about InterSystems IRIS list structures, see $LIST and related functions.
%DLIST and %SelectMode
You can use the %SelectMode property to specify the data display mode returned by %DLIST: 0=Logical (the default), 1=ODBC, 2=Display.
Note that %DLIST in ODBC mode separates column value lists with commas, and $LISTTOSTRING (by default) returns elements within a %List column value separated with commas.
%DLIST and ORDER BY
The %DLIST function combines the values of a table column from multiple rows into %List structured list of values. Because an ORDER BY clause is applied to the query result set after all aggregate fields are evaluated, ORDER BY cannot directly affect the sequence of values within this list. Under certain circumstances, %DLIST results may appear in sequential order, but this ordering should not be relied upon. The values listed within a given aggregate result value cannot be explicitly ordered.