SQL Quest › SQL Interview Questions › Subqueries & CTEs
Every Film by a Director Who Once Hit 8.5
A retrospective is being programmed around directors with at least one great film. The brief: if a director ever reached 8.5, screen everything of theirs in the table.
Show exactly these 4 columns, in this order: title, year, rating, director. No aliases, no rounding. Include every movie whose director appears at least once in the table with a rating of 8.5 or higher. Order by director ascending, then year ascending, then title ascending.
The new idea: the subquery can read the same table you are already selecting from. (SELECT director FROM movies WHERE rating >= 8.5) returns a column of names — repeats and all, which IN does not mind — and the outer query keeps every row whose director is on that list.
Look at what comes back: films rated well below 8.5 are in the result, because the test is on the director, not on the row. That is exactly why a plain WHERE rating >= 8.5 cannot answer this question.
Solve it in the browser editor →
Runs on SQLite in your browser, graded against the expected result, no signup. A wrong answer gets a diagnosis, not just "incorrect".
Schema
movies
| id | title | year | genre | rating | votes | revenue_millions | runtime | director |
|---|---|---|---|---|---|---|---|---|
| 1 | Guardians of the Galaxy | 2014 | Action | 8.1 | 757074 | 333.13 | 121 | James Gunn |
| 2 | Prometheus | 2012 | Adventure | 7 | 485820 | 126.46 | 124 | Ridley Scott |
| 3 | Split | 2016 | Horror | 7.3 | 157606 | 138.12 | 117 | M. Night Shyamalan |
Expected output: 36 rows — including their weaker films
Hint
SELECT, Subquery, IN, and open the hint there if you stall.Concepts
SELECT Subquery IN WHERE
Practise the topic: SQL practice questions · CTE practice
Related questions
Where would this cost you points in an interview?
Ten questions, no signup: a Skillmap across nine SQL skills and the one to fix first.
Take the readiness test