Skip to content

Commit 8b85a84

Browse files
author
Chris Erdmann
authored
Change source (code) to sql
1 parent 8baf872 commit 8b85a84

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

_episodes/06-joins-aliases.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ FROM articles
2626
JOIN journals
2727
ON articles.ISSNs = journals.ISSNs;
2828
~~~
29-
{: .source}
29+
{: .sql}
3030

3131
`ON` is similar to `WHERE`, it filters things out according to a test condition. We use the `table.colname` format to tell the SQL manager what column in which table we are referring to.
3232

@@ -38,7 +38,7 @@ FROM articles
3838
JOIN journals
3939
USING (ISSNs);
4040
~~~
41-
{: .source}
41+
{: .sql}
4242

4343
This figure shows the relations between the tables and helps to visualise joining or linking the tables in the database:
4444
![Articles Database](../assets/img/articles-erd.png)
@@ -52,7 +52,7 @@ FROM articles
5252
JOIN journals
5353
ON articles.ISSNs = journals.ISSNs;
5454
~~~
55-
{: .source}
55+
{: .sql}
5656

5757
Joins can be combined with sorting, filtering, and aggregation. So, if we wanted the average number of authors for articles on each journal, we can use the following query:
5858

@@ -63,7 +63,7 @@ JOIN journals
6363
ON articles.ISSNs = journals.ISSNs
6464
GROUP BY articles.ISSNs;
6565
~~~
66-
{: .source}
66+
{: .sql}
6767

6868
The `ROUND` function allows us to round the `Author_Count` number returned by the `AVG` function by 2 decimal places.
6969

@@ -92,7 +92,7 @@ ON articles.ISSNs = journals.ISSNs
9292
JOIN publishers
9393
ON publishers.id = journals.PublisherId;
9494
~~~
95-
{: .source}
95+
{: .sql}
9696
9797
> ## Challenge:
9898
>
@@ -129,7 +129,7 @@ FROM articles AS ar
129129
JOIN journals AS jo
130130
ON ar.ISSNs = jo.ISSNs;
131131
~~~
132-
{: .source}
132+
{: .sql}
133133
134134
And column names:
135135
@@ -139,15 +139,15 @@ FROM articles AS ar
139139
JOIN journals AS jo
140140
ON ar.issns = jo.issns;
141141
~~~
142-
{: .source}
142+
{: .sql}
143143
144144
The `AS` isn't technically required, so you could do:
145145
146146
~~~
147147
SELECT a.Title t
148148
FROM articles a;
149149
~~~
150-
{: .source}
150+
{: .sql}
151151
152152
But using `AS` is much clearer so it is good style to include it.
153153

0 commit comments

Comments
 (0)