w3resource
SQL exercises

SQL exercises on movie Database: Find all the movies with year, genres, and name of the director

SQL movie Database: Join Exercise-8 with Solution

8. Write a query in SQL to list all the movies with year, genres, and name of the director.

Sample table: movie


Sample table: genres


Sample table: movie_genres


Sample table: director


Sample table: movie_direction


Sample Solution:

SELECT mov_title, mov_year, gen_title, dir_fname, dir_lname
FROM movie
NATURAL JOIN movie_genres
NATURAL JOIN genres
NATURAL JOIN movie_direction
NATURAL JOIN director;

Sample Output:

                     mov_title                      | mov_year |      gen_title       |      dir_fname       |      dir_
----------------------------------------------------+----------+----------------------+----------------------+----------
 Vertigo                                            |     1958 | Mystery              | Alfred               | Hitchcock
 The Innocents                                      |     1961 | Horror               | Jack                 | Clayton
 Lawrence of Arabia                                 |     1962 | Adventure            | David                | Lean
 The Deer Hunter                                    |     1978 | War                  | Michael              | Cimino
-- More  --

Practice Online


Movie database model

Query Visualization:

Duration:

Query visualization of Find all the movies with year, genres, and name of the director - Duration

Rows:

Query visualization of Find all the movies with year, genres, and name of the director - Rows

Cost:

Query visualization of Find all the movies with year, genres, and name of the director - Cost

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a query in SQL to list all the movies with year and genres.
Next: Write a query in SQL to list all the movies with title, year, date of release, movie duration, and first and last name of the director which released before 1st January 1989, and sort the result set according to release date from highest date to lowest.

What is the difficulty level of this exercise?



New Content: Composer: Dependency manager for PHP, R Programming