Skip to content

Commit

Permalink
Merge pull request #3964 from szarnyasg/nits-20241024g
Browse files Browse the repository at this point in the history
Add note on self-joins
  • Loading branch information
szarnyasg authored Oct 24, 2024
2 parents b5afb62 + a4e1330 commit ca73ea4
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions docs/sql/query_syntax/from.md
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,26 @@ FROM trades t
ASOF LEFT JOIN prices p USING (symbol, "when");
```

### Self-Joins

DuckDB allows self-joins for all types of joins.
Note that tables need to be aliased, using the same table name without aliases will result in an error:

```sql
CREATE TABLE t(x int);
SELECT * FROM t JOIN t USING(x);
```

```console
Binder Error: Duplicate alias "t" in query!
```

Adding the aliases allows the query to parse successfully:

```sql
SELECT * FROM t AS t t1 JOIN t t2 USING(x);
```

## `FROM`-First Syntax

DuckDB's SQL supports the `FROM`-first syntax, i.e., it allows putting the `FROM` clause before the `SELECT` clause or completely omitting the `SELECT` clause. We use the following example to demonstrate it:
Expand Down

0 comments on commit ca73ea4

Please sign in to comment.