diff --git a/docs/user-guide/src/SUMMARY.md b/docs/user-guide/src/SUMMARY.md index e2ddcb0a4e89..0fced3bb3dea 100644 --- a/docs/user-guide/src/SUMMARY.md +++ b/docs/user-guide/src/SUMMARY.md @@ -20,7 +20,12 @@ - [Introduction](introduction.md) - [Example Usage](example-usage.md) -- [Use as a Library](library.md) +- [Use as a Library](library.md) +- [SQL Reference](sql/introduction.md) + - [SELECT](sql/select.md) + - [DDL](sql/ddl.md) + - [CREATE EXTERNAL TABLE](sql/ddl.md) + - [Distributed](distributed/introduction.md) - [Create a Ballista Cluster](distributed/deployment.md) - [Docker](distributed/standalone.md) diff --git a/docs/user-guide/src/sql/ddl.md b/docs/user-guide/src/sql/ddl.md new file mode 100644 index 000000000000..cb1665792d96 --- /dev/null +++ b/docs/user-guide/src/sql/ddl.md @@ -0,0 +1,20 @@ + + +# DDL diff --git a/docs/user-guide/src/sql/introduction.md b/docs/user-guide/src/sql/introduction.md new file mode 100644 index 000000000000..89ed2777618d --- /dev/null +++ b/docs/user-guide/src/sql/introduction.md @@ -0,0 +1,20 @@ + + +# SQL Reference diff --git a/docs/user-guide/src/sql/select.md b/docs/user-guide/src/sql/select.md new file mode 100644 index 000000000000..777b4ff61e5d --- /dev/null +++ b/docs/user-guide/src/sql/select.md @@ -0,0 +1,133 @@ + + +# SELECT syntax + +The queries in DataFusion scan data from tables and return 0 or more rows. +In this documentation we describe the SQL syntax in DataFusion. + +DataFusion supports the following syntax for queries: + + +[ [WITH](#with-clause) with_query [, ...] ]
+[SELECT](#select-clause) select_expr [, ...]
+[ [FROM](#from-clause) from_item [, ...] ]
+[ [WHERE](#where-clause) condition ]
+[ [GROUP BY](#group-by-clause) grouping_element [, ...] ]
+[ [HAVING](#having-clause) condition]
+[ [UNION](#union-clause) [ ALL | select ]
+[ [ORDER BY](#order-by-clause) expression [ ASC | DESC ] [, ...] ]
+[ [LIMIT](#limit-clause) count ]
+ +
+ +# WITH clause + +A with clause allows to give names for queries and reference them by name. + +```sql +WITH x AS (SELECT a, MAX(b) AS b FROM t GROUP BY a) +SELECT a, b FROM x; +``` + +# SELECT clause + + +Example: + +```sql +SELECT a, b, a + b FROM table +``` + + +# FROM clause + +Example: +```sql +SELECT t.a FROM table AS t +``` + + +# WHERE clause + +Example: + +```sql +SELECT a FROM table WHERE a > 10 +``` + +# GROUP BY clause + +Example: + +```sql +SELECT a, b, MAX(c) FROM table GROUP BY a, b +``` + + +# HAVING clause + +Example: + +```sql +SELECT a, b, MAX(c) FROM table GROUP BY a, b HAVING MAX(c) > 10 +``` + +# UNION clause + +Example: + +```sql +SELECT + a, + b, + c +FROM table1 +UNION ALL +SELECT + a, + b, + c +FROM table2 +``` + +# ORDER BY clause + +Orders the results by the referenced expression. By default it uses ascending order (`ASC`). +This order can be changed to descending by adding `DESC` after the order-by expressions. + +Examples: + +```sql +SELECT age, person FROM table ORDER BY age; +SELECT age, person FROM table ORDER BY age DESC; +SELECT age, person FROM table ORDER BY age, person DESC; +``` + + +# LIMIT clause + +Limits the number of rows to be a maximum of `count` rows. `count` should be a non-negative integer. + +Example: + +```sql +SELECT age, person FROM table +LIMIT 10 +``` \ No newline at end of file