Instruction
Excellent! We have one more exercise for you before the end of this part. You are going to write your longest SQL query ever and you'll apply knowledge from both of the parts you've mastered so far. Are you ready?
Exercise
Select the id, 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 and the column production_year as produced_in. Select only those movies:
- whose title contains a letter 'a' and which were filmed after 2000,
or - whose director was born between 1945 and 1995.
Stuck? Here's a hint!
- Select proper columns from the
movieanddirectortables. - Start by writing the construction for the
WHEREcondition, like so:
WHERE (...)
OR (...) - Fill in both of the parenthesis:
title LIKE '%a%' AND production_year > 2000birth_year between 1945 AND 1995
And when you're really stuck, use the answer:
SELECT movie.id, title, production_year AS produced_in, name, birth_year AS born_in FROM movie JOIN director ON director.id = director_id WHERE (title LIKE '%a%' AND production_year > 2000) OR (birth_year between 1945 AND 1995);




