Skip to content

Commit

Permalink
Merge pull request #325 from spbail/gh-pages
Browse files Browse the repository at this point in the history
Update 02-sql-aggregation.md
  • Loading branch information
ChristinaLK authored Jun 2, 2021
2 parents 2aa5df5 + 7836119 commit e39e3b1
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 e39e3b1

Please sign in to comment.