Kickstart 2020 with new opportunities! - hours only!Up to 80% off on all courses and bundles.-Close
How to query more than one table
Creating JOINs
Referencing columns
Let's practice
12. Put your skills into practice

Instruction

Nice! Let's put into practice everything we've learnt so far. Are you ready? This example is going to be slightly more complicated, so make sure you remember everything from this part of the course.

Exercise

Select the title and production_year columns from the movie table, and the name and birth_year columns from the director table in such a way that a movie is shown together with its director.

Show the column birth_year as born_in. Select only those movies which were filmed when their director was younger than 40 (i.e. the difference between production_year and birth_year must be less than 40).

Stuck? Here's a hint!

Type:

SELECT
  title,
  production_year,
  name,
  birth_year AS born_in
FROM movie
JOIN director
  ON director_id = director.id
WHERE (production_year - birth_year) < 40;