> ## Documentation Index
> Fetch the complete documentation index at: https://docs.firebolt.io/llms.txt
> Use this file to discover all available pages before exploring further.

> Reference material for STRING_AGG function

# STRING_AGG

Concatenates non-`NULL` string values from a group into a single string, with each value separated by the specified delimiter.

## Syntax

```sql theme={"theme":{"light":"css-variables","dark":"css-variables"}}
STRING_AGG(<expression>, <delimiter>)
```

## Parameters

| Parameter      | Description                                                 | Supported input types |
| :------------- | :---------------------------------------------------------- | :-------------------- |
| `<expression>` | The string expression to aggregate.                         | `TEXT`                |
| `<delimiter>`  | The string placed between each pair of concatenated values. | `TEXT`                |

## Return Type

`TEXT`

## Remarks

* `NULL` values in `<expression>` are silently skipped.
* If all input values are `NULL`, or if the input set is empty, `STRING_AGG` returns `NULL`.
* No specific order for the concatenation of values is guaranteed. To concatenate in a specific order, use [ARRAY\_AGG](/reference-sql/functions-reference/aggregation/array-agg), [ARRAY\_SORT](/reference-sql/functions-reference/array/array-sort), and [ARRAY\_TO\_STRING](/reference-sql/functions-reference/array/array-to-string).
* An empty `<delimiter>` (empty string `''`) concatenates values without any separator.

## Example

The `levels` table contains the following values:

<div className="query-window">
  ```
  SELECT level, name, leveltype FROM levels ORDER BY level;
  ```

  | level <span>int null</span> | name <span>text null</span> | leveltype <span>text null</span> |
  | :-------------------------- | :-------------------------- | :------------------------------- |
  | 1                           | Thunderbolt Circuit         | FastestLap                       |
  | 2                           | Velocity Vale               | FirstToComplete                  |
  | 3                           | Raceway Ridge               | FastestLap                       |
  | 4                           | Nitro Narrows               | FirstToComplete                  |
  | 5                           | Thunder Road                | FirstToComplete                  |
  | 6                           | Burnout Boulevard           | Drift                            |
  | 7                           | Speed Street                | FastestLap                       |
  | 8                           | Racing Ravine               | FastestLap                       |
  | 9                           | Drift District              | Drift                            |
  | 10                          | Acceleration Alley          | FirstToComplete                  |

  <p><span>Rows: 10</span><span>Execution time: 5.13ms</span></p>
</div>

The following example concatenates all level names within each `leveltype`, separated by commas:

<div className="query-window">
  ```
  SELECT leveltype, STRING_AGG(name, ', ') AS levels
  FROM levels
  GROUP BY leveltype
  ORDER BY leveltype;
  ```

  | leveltype <span>text null</span> | levels <span>text null</span>                                   |
  | :------------------------------- | :-------------------------------------------------------------- |
  | Drift                            | Burnout Boulevard, Drift District                               |
  | FastestLap                       | Thunderbolt Circuit, Raceway Ridge, Speed Street, Racing Ravine |
  | FirstToComplete                  | Velocity Vale, Nitro Narrows, Thunder Road, Acceleration Alley  |

  <p><span>Rows: 3</span><span>Execution time: 10.18ms</span></p>
</div>

The following example shows that `NULL` values are skipped:

<div className="query-window">
  ```
  SELECT STRING_AGG(a, ',') AS result
  FROM (VALUES ('a'), (NULL), ('b'), ('c')) AS t(a);
  ```

  | result <span>text null</span> |
  | :---------------------------- |
  | a,b,c                         |

  <p><span>Rows: 1</span><span>Execution time: 3.82ms</span></p>
</div>
