---
title: SQL Pipeline Syntax
description: Compose queries from chained operators with SQL pipeline syntax in Databricks SQL and Databricks Runtime.
canonical_url: https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-qry-pipeline
---

# SQL Pipeline Syntax

**Applies to:** ![check marked yes](https://docs.databricks.com/aws/en/images/icons/check.png) Databricks SQL ![check marked yes](https://docs.databricks.com/aws/en/images/icons/check.png) Databricks Runtime 16.2 and above

Databricks supports SQL pipeline syntax which allows composing queries from combinations of chained operators.

* Any query can have zero or more pipe operators as a suffix, delineated by the pipe token `|>` (or `|` in Databricks Runtime 18.0 or above).
* Each [piped operation](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-qry-select-pipeop.md) starts with one or more SQL keywords followed by its own grammar.
* Operators can apply in any order, any number of times.
* Typically [FROM relation\_name](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-qry-select-table-reference.md) is used to start a pipeline, but any [query](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-qry-query.md) can start a pipeline.

## Syntax

```
{ FROM | TABLE } relation_name { |> piped_operation } [ ...]
```

In Databricks Runtime 18.0 and above, you can use `|` in place of `|>`:

```
{ FROM | TABLE } relation_name { | piped_operation } [ ...]
```

## Parameters

* **[relation\_name](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-names.md#table-name)**

  Identifies a table or view to be used as the input for the pipeline.
  If the table or view cannot be found, Databricks raises a [TABLE\_OR\_VIEW\_NOT\_FOUND](https://docs.databricks.com/aws/en/error-messages/table-or-view-not-found-error-class.md) error.

* **[piped\_operation](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-qry-select-pipeop.md)**

  An operation consuming the preceding query or pipe operation.
  See [piped\_operation](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-qry-select-pipeop.md) for details.

## Common error conditions

* [TABLE\_OR\_VIEW\_NOT\_FOUND](https://docs.databricks.com/aws/en/error-messages/table-or-view-not-found-error-class.md)

## Example

This is query 13 from the TPC-H benchmark written in ANSI SQL:

```sql
> SELECT c_count, COUNT(*) AS custdist
    FROM
    (SELECT c_custkey, COUNT(o_orderkey) c_count
      FROM customer
      LEFT OUTER JOIN orders ON c_custkey = o_custkey
                             AND o_comment NOT LIKE '%unusual%packages%'
     GROUP BY c_custkey
  ) AS c_orders
  GROUP BY c_count
  ORDER BY custdist DESC, c_count DESC;
```

To write the same logic using SQL pipe operators, you can express it like this:

```sql
> FROM customer
  |> LEFT OUTER JOIN orders ON c_custkey = o_custkey
                            AND o_comment NOT LIKE '%unusual%packages%'
  |> AGGREGATE COUNT(o_orderkey) c_count
     GROUP BY c_custkey
  |> AGGREGATE COUNT(*) AS custdist
     GROUP BY c_count
  |> ORDER BY custdist DESC, c_count DESC;
```

## Related articles

* [Query](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-qry-query.md)
* [Piped operation](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-qry-select-pipeop.md)
