21.1. SQL Part 3 - Joins

21.1.1. Reading

Read the following articles, and watch the videos.

Joins:

SQL join types.

SQL | Join (Inner, Left, Right and Full Joins).

SQL Joins Explained |¦| Joins in SQL |¦| SQL Tutorial Part 1.

SQL Joins Examples |¦| Joins in SQL |¦| SQL Tutorial Part 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.

SQL HAVING.

Intermediate SQL Tutorial | Having Clause.

21.1.2. Check Your Understanding

Question

What does an inner join do?

  1. Returns results with matching rows in both tables
  2. Returns results with all the rows from the left table with null values for unmatched rows from the right table
  3. Returns results with all the rows from the right table with null values for unmatched rows from the left table
  4. Returns results from all the rows from both tables with null values filled in for all unmatched rows.

Question

What does a full (outer) join do?

  1. Returns results with matching rows in both tables
  2. Returns results with all the rows from the left table with null values for unmatched rows from the right table
  3. Returns results with all the rows from the right table with null values for unmatched rows from the left table
  4. 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?

  1. SELECT, WHERE, HAVING, GROUP BY
  2. SELECT, HAVING, WHERE, GROUP BY
  3. SELECT, WHERE, GROUP BY, HAVING
  4. SELECT, HAVING, GROUP BY, WHERE

Question

Can you use aggregates with the HAVING Clause?

  1. True
  2. False

Question

Can you use aggregates with the WHERE clause?

  1. True
  2. False

Question

In your own words, what is the difference between the WHERE clause and the HAVING clause?