

# SELECT statement in DuckDB

Use `SELECT` to read rows from tables, files, table functions, and inline values, and to filter, group, sort, and combine them. Along with the standard SQL clauses, you can use the additions that DuckDB provides. These include FROM-first syntax, star expressions with `EXCLUDE` and `REPLACE`, `GROUP BY ALL`, `ORDER BY ALL`, and `QUALIFY`. They also include `ASOF` and `POSITIONAL` joins, `UNION BY NAME`, and `PIVOT` and `UNPIVOT`.

Each query is one SQL statement. Without an `ORDER BY` clause, the order of the rows in a result is not guaranteed.

The examples for these clauses use inline `VALUES` lists and two small tables in a database named `sales_db`. The `sales_parquet` table is a Hive table in Parquet format that holds six orders, and the `orders_iceberg` table is an Iceberg table that holds the first three of those orders. Both tables have the columns `order_id` (`INTEGER`), `customer` (`VARCHAR`), `region` (`VARCHAR`), `amount` (`DECIMAL(10,2)`), and `order_date` (`DATE`). The `amount` column holds the order total in US dollars (USD). For every row of `sales_parquet`, see the first example in [`SELECT` list](duckdb-statement-select-select-list.md).

## Synopsis
<a name="athena-duckdb-statement-select-synopsis"></a>

```sql
[ WITH [ RECURSIVE ] {{with_query}} [, ...] ]
SELECT [ ALL | DISTINCT ] {{select_list}}
[ FROM {{from_item}} [, ...] ]
[ WHERE {{condition}} ]
[ GROUP BY { ALL | {{grouping_element}} [, ...] } ]
[ HAVING {{condition}} ]
[ WINDOW {{window_name}} AS ( {{window_definition}} ) [, ...] ]
[ QUALIFY {{condition}} ]
[ USING SAMPLE {{size}} [ ROWS | PERCENT | % ] [ ( {{method}}
    [, {{seed}} ] ) ] ]
[ { UNION [ ALL ] [ BY NAME ] | INTERSECT
    [ ALL ] | EXCEPT [ ALL ] } {{select}} ]
[ ORDER BY { ALL [ ASC | DESC ] | {{expression}}
    [ ASC | DESC ] [ NULLS { FIRST | LAST } ]
    [, ...] } ]
[ LIMIT { {{count}} | {{percentage}} % } ]
[ OFFSET {{start}} ]
```

**Topics**
+ [Synopsis](#athena-duckdb-statement-select-synopsis)
+ [`SELECT` list](duckdb-statement-select-select-list.md)
+ [Star expressions](duckdb-statement-select-star-expressions.md)
+ [`DISTINCT` and `ALL`](duckdb-statement-select-distinct.md)
+ [`FROM` clause](duckdb-statement-select-from.md)
+ [FROM-first syntax](duckdb-statement-select-from-first.md)
+ [`VALUES` lists](duckdb-statement-select-values.md)
+ [Subqueries](duckdb-statement-select-subqueries.md)
+ [Time travel queries on Iceberg tables](duckdb-statement-select-time-travel.md)
+ [Joins](duckdb-statement-select-joins.md)
+ [`SEMI` and `ANTI` joins](duckdb-statement-select-semi-anti-joins.md)
+ [`LATERAL` joins](duckdb-statement-select-lateral-joins.md)
+ [`ASOF` joins](duckdb-statement-select-asof-joins.md)
+ [`POSITIONAL` joins](duckdb-statement-select-positional-joins.md)
+ [`WHERE` clause](duckdb-statement-select-where.md)
+ [`GROUP BY` clause](duckdb-statement-select-group-by.md)
+ [`HAVING` clause](duckdb-statement-select-having.md)
+ [`WINDOW` clause](duckdb-statement-select-window.md)
+ [`QUALIFY` clause](duckdb-statement-select-qualify.md)
+ [`ORDER BY` clause](duckdb-statement-select-order-by.md)
+ [`LIMIT` and `OFFSET` clauses](duckdb-statement-select-limit.md)
+ [`USING SAMPLE` clause](duckdb-statement-select-sample.md)
+ [`WITH` clause (common table expressions)](duckdb-statement-select-with.md)
+ [Set operations: `UNION`, `INTERSECT`, and `EXCEPT`](duckdb-statement-select-set-operations.md)
+ [`PIVOT`](duckdb-statement-select-pivot.md)
+ [`UNPIVOT`](duckdb-statement-select-unpivot.md)