mirror of
https://github.com/treffynnon/sqlstyle.guide.git
synced 2025-03-09 12:49:51 -05:00
JOINs
This commit is contained in:
parent
fb6eac76ed
commit
3603d371de
1 changed files with 9 additions and 12 deletions
|
@ -88,7 +88,7 @@ FROM staff;
|
||||||
```sql
|
```sql
|
||||||
SELECT first_name AS fn
|
SELECT first_name AS fn
|
||||||
FROM staff AS s1
|
FROM staff AS s1
|
||||||
JOIN students AS s2
|
JOIN students AS s2
|
||||||
ON s2.mentor_id = s1.staff_num;
|
ON s2.mentor_id = s1.staff_num;
|
||||||
```
|
```
|
||||||
```sql
|
```sql
|
||||||
|
@ -220,8 +220,7 @@ This allows the reader to quickly scan for the important building blocks of the
|
||||||
|
|
||||||
#### Joins
|
#### Joins
|
||||||
|
|
||||||
Joins should be indented to the other side of the river and grouped with a new
|
Joins should be indented 2 spaces right from the `FROM` keyword
|
||||||
line where necessary.
|
|
||||||
|
|
||||||
Single line `JOIN`s are fine for simple situations
|
Single line `JOIN`s are fine for simple situations
|
||||||
|
|
||||||
|
@ -250,9 +249,7 @@ Indent them until the closing parentheses.
|
||||||
WITH my_tmp_table AS (
|
WITH my_tmp_table AS (
|
||||||
SELECT r.last_name
|
SELECT r.last_name
|
||||||
FROM riders AS r
|
FROM riders AS r
|
||||||
INNER JOIN bikes b
|
INNER JOIN bikes b ON r.bike_vin_num = b.vin_num
|
||||||
ON r.bike_vin_num = b.vin_num
|
|
||||||
AND r.bike_lane = r.lane
|
|
||||||
)
|
)
|
||||||
|
|
||||||
SELECT *
|
SELECT *
|
||||||
|
|
Loading…
Reference in a new issue