21.1. SQL Part 3 - Joins¶
Read the following articles, and watch the videos:
21.1.1. SQL JOINS
¶
21.1.2. HAVING
clause¶
The HAVING
clause is very similar to a WHERE
clause in that it is used to filter result sets. However, we cannot use the WHERE
clause with aggregate functions. Instead, we have to use the HAVING
clause. If you want to use an aggregate function with a join
, then you need to make use of this new clause. The HAVING
clause is often used with GROUP BY
.
21.1.3. Check Your Understanding¶
Question
What does an INNER JOIN
do?
Returns results with matching rows in both tables
Returns results with all the rows from the left table with null values for unmatched rows from the right table
Returns results with all the rows from the right table with null values for unmatched rows from the left table
Returns results from all the rows from both tables with null values filled in for all unmatched rows.
Question
What does a FULL JOIN
or OUTER JOIN
do?
Returns results with matching rows in both tables
Returns results with all the rows from the left table with null values for unmatched rows from the right table
Returns results with all the rows from the right table with null values for unmatched rows from the left table
Returns results from all the rows from both tables with null values filled in for all unmatched rows
Question
In your own words what is the difference between a RIGHT JOIN
and a LEFT JOIN
?
Question
In what order do the following clauses go when writing a query?
SELECT, WHERE, HAVING, GROUP BY
SELECT, HAVING, WHERE, GROUP BY
SELECT, WHERE, GROUP BY, HAVING
SELECT, HAVING, GROUP BY, WHERE
Question
Can you use aggregates with the HAVING
Clause?
True
False
Question
Can you use aggregates with the WHERE
clause?
True
False
Question
In your own words, what is the difference between the WHERE
clause and the HAVING
clause?