Skip to content

Commit

Permalink
Update 02-sql-aggregation.md
Browse files Browse the repository at this point in the history
This addresses #284. I also split up table and column aliases to make the difference clearer (I totally missed the table alias during the first read through!), and added a tiny bit more explanation.
  • Loading branch information
spbail authored May 12, 2021
1 parent d44834e commit 7836119
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions episodes/02-sql-aggregation.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,21 +117,33 @@ species captured, ordered by the count:
## Aliases
As queries get more complex names can get long and unwieldy. To help make things
clearer we can use aliases to assign new names to things in the query.
As queries get more complex, the expressions we use can get long and unwieldy. To help make things
clearer in the query and in its output, we can use aliases to assign new names to things in the query.
We can use aliases in column names or table names using `AS`:
We can use aliases in column names using `AS`:
SELECT MAX(year) AS last_surveyed_year
FROM surveys;
The `AS` isn't technically required, so you could do
SELECT MAX(year) yr
FROM surveys surv;
SELECT MAX(year) last_surveyed_year
FROM surveys;
but using `AS` is much clearer so it is good style to include it.
We can not only alias column names, but also table names in the same way:
SELECT *
FROM surveys AS surv;
And again, the `AS` keyword is not required, so this works, too:
SELECT *
FROM surveys surv;
Aliasing table names can be helpful when working with queries that involve multiple tables; you will learn more about this later.
## The `HAVING` keyword
In the previous episode, we have seen the keyword `WHERE`, allowing to
Expand Down

0 comments on commit 7836119

Please sign in to comment.