Skip to content

Commit

Permalink
chore: Backport #3137 to web (#3138)
Browse files Browse the repository at this point in the history
Co-authored-by: Maximilian Roos <5635139+max-sixty@users.noreply.github.com>
  • Loading branch information
prql-bot and max-sixty committed Jul 27, 2023
1 parent 8fd71c1 commit ba215ed
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
16 changes: 11 additions & 5 deletions web/book/src/reference/stdlib/transforms/join.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@
Adds columns from another table, matching rows based on a condition.

```prql no-eval
join side:{inner|left|right|full} table (conditions)
join side:{inner|left|right|full} table (condition)
```

## Parameters

- `side` decides which rows to include, defaulting to `inner`.
- Table reference
- List of conditions
- The result of join operation is a cartesian (cross) product of rows from
both tables, which is then filtered to match all of these conditions.
- Relation reference
- A condition
- If name is the same from both tables, it can be expressed with only `==col`.

## Examples
Expand All @@ -27,6 +25,14 @@ from employees
join side:left p=positions (employees.id==p.employee_id)
```

```prql
from tracks
join side:left artists (
artists.id==tracks.artist_id && artists.country=='UK'
# As an alternative to filtering
)
```

## Self equality operator

If the join conditions are of form `left.x == right.x`, we can use "self
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
source: web/book/tests/documentation/book.rs
expression: "from tracks\njoin side:left artists (\n artists.id==tracks.artist_id && artists.country=='UK'\n # As an alternative to filtering\n)\n"
---
SELECT
tracks.*,
artists.*
FROM
tracks
LEFT JOIN artists ON artists.id = tracks.artist_id
AND artists.country = 'UK'

0 comments on commit ba215ed

Please sign in to comment.