View a markdown version of this page

SELECT statement in DuckDB - Amazon Athena

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.

Synopsis

[ 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 ]