Skip to content

Commit

Permalink
Update 01-query-select.md
Browse files Browse the repository at this point in the history
  • Loading branch information
soyeric128 committed Feb 11, 2025
1 parent d89105a commit af1710d
Showing 1 changed file with 24 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,20 @@ title: SELECT
---
import FunctionDescription from '@site/src/components/FunctionDescription';

<FunctionDescription description="Introduced or updated: v1.2.435"/>
<FunctionDescription description="Introduced or updated: v1.2.690"/>

import DetailsWrap from '@site/src/components/DetailsWrap';

Retrieves data from a table.



## Syntax

```sql
[WITH]
SELECT
[ALL | DISTINCT]
[ TOP <n> ]
<select_expr> | <col_name> [[AS] <alias>] | $<col_position> [, ...] |
<select_expr> | <col_name> [[AS] <alias>] | $<col_position> [, ...] | *
COLUMNS <expr>
[EXCLUDE (<col_name1> [, <col_name2>, <col_name3>, ...] ) ]
[FROM table_references]
Expand All @@ -39,17 +37,6 @@ SELECT

## SELECT Clause

```sql
SELECT number FROM numbers(3);
+--------+
| number |
+--------+
| 0 |
| 1 |
| 2 |
+--------+
```

### AS Keyword

In Databend, you can use the AS keyword to assign an alias to a column. This allows you to provide a more descriptive and easily understandable name for the column in both the SQL statement and the query result:
Expand Down Expand Up @@ -155,7 +142,7 @@ SELECT * EXCLUDE (id,lastname) FROM allemployees;
| Macy | F |
```

### COLUMNS
### COLUMNS Keyword

The COLUMNS keyword provides a flexible mechanism for column selection based on literal regular expression patterns and lambda expressions.

Expand Down Expand Up @@ -232,6 +219,27 @@ SELECT a, $2 FROM t1;
+---+-------+
```

### Retrieving All Columns

The `SELECT *` statement is used to retrieve all columns from a table or query result. It is a convenient way to fetch complete data sets without specifying individual column names.

This example returns all columns from my_table:

```sql
SELECT * FROM my_table;
```

Databend extends SQL syntax by allowing queries to start with `FROM <table>` without explicitly using `SELECT *`:
```sql
FROM my_table;
```

This is equivalent to:

```sql
SELECT * FROM my_table;
```

## FROM Clause

The FROM clause in a SELECT statement specifies the source table or tables from which data will be queried. You can also improve code readability by placing the FROM clause before the SELECT clause, especially when managing a lengthy SELECT list or aiming to quickly identify the origins of selected columns.
Expand Down

0 comments on commit af1710d

Please sign in to comment.