How to query more than one table
Creating JOINs
Referencing columns
10. Filter the joined tables
Let's practice

Instruction

Amazing job! Now that we know how to work with columns, let's find out how to filter the results even further:

SELECT
  Person.Id,
  Car.Model
FROM Person
JOIN Car
  ON Person.Id = Car.OwnerId
WHERE Person.Age < 25;

The new part here is the WHERE clause. Now, we only look for pairs of cars and owners for which the owner is younger than 25. Be sure to include the table name in the condition (Person.Age).

Exercise

Select all columns from the tables Movie and Director such that each movie is shown together with its director. Select only those movies that were produced after 2000.

Stuck? Here's a hint!

Type:

SELECT
  *
FROM Movie
JOIN Director
  ON Movie.DirectorId = Director.Id
WHERE Movie.ProductionYear > 2000;