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

# SUBSTRING_INDEX

> Returns a prefix or suffix selected by delimiter occurrence count.

<div className="e6-meta"><span className="e6-eyebrow e6-eyebrow--quiet">Scalar function</span></div>

Returns NULL for NULL arguments.

## Syntax

### Scalar

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
substring_index(value, delimiter, count)
```

## Arguments

| Name | Type | Required | Description |
| - | - | - | - |
| value | STRING | Yes | The string. |
| delimiter | STRING | Yes | Literal delimiter. |
| count | INTEGER | Yes | Positive searches from left; negative from right. |

## Returns

* Type: STRING
* Possible values: The selected prefix or suffix.
* NULL behavior: Returns NULL for NULL arguments.

## Properties

| Property | Value |
| - | - |
| Deterministic | Yes |
| Supports window usage | No |
| Exact result | Yes |

## Usage notes

* Zero count or empty delimiter returns an empty string. If abs(count) exceeds the number of delimiter occurrences, returns the whole input.

## Examples

### Typical behavior

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
SELECT substring_index('www.apache.org', '.', 1) AS prefix, substring_index('www.apache.org', '.', -1) AS suffix;
```

| prefix | suffix |
| - | - |
| www | org |

### Keep multiple delimiter-separated parts

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
SELECT substring_index('a.b.c.d', '.', 2) AS first_two, substring_index('a.b.c.d', '.', -2) AS last_two;
```

| first\_two | last\_two |
| - | - |
| a.b | c.d |

## Limitations

* Use SUBSTRING\_INDEX. SUBSTR\_INDEX is not an established SQL alias.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.