GROUP_CONCAT

fun GROUP_CONCAT(column: KQLiteColumn<*>, separator: String? = null, distinct: Boolean = false): KQLiteColumn<String>

Represents the SQL GROUP_CONCAT() aggregate function.

This function returns a single string consisting of all non-NULL values from a group, concatenated together.

Example

// SELECT GROUP_CONCAT(firstName, ', ') FROM Employees WHERE department_id = 5;
val allNames = GROUP_CONCAT(Employees.firstName, ", ")
val cursor =
Employees
.select(allNames)
.where {
Employees.reportsTo EQ 5
}.execute()
println(cursor[allNames])
cursor.close()

// Concatenate only distinct cities.
// SELECT GROUP_CONCAT(DISTINCT city) FROM Employees;
val distinctCities = GROUP_CONCAT(Employees.city, distinct = true)
val cursor2 =
Employees
.select(distinctCities)
.execute()
println(cursor2[distinctCities])
cursor2.close()

Return

A KQLiteColumn representing the concatenated string. The result is NULL if the group is empty.

Author

MOHAMMAD AZIM ANSARI

Parameters

column

The column whose values are to be concatenated.

separator

The string to use as a separator between concatenated values. If null or omitted, a comma (,) is used by default in SQLite.

distinct

If true, only DISTINCT (unique) non-NULL values in the column are concatenated. Defaults to false.

See also