w3resource
SQL exercises

SQL exercises on movie Database: Find the highest-rated Mystery movie, and report the title, year, and rating

SQL movie Database: Join Exercise-22 with Solution

22. Write a query in SQL to find the highest-rated Mystery movie, and report the title, year, and rating.

Sample table: movie


Sample table: genres


Sample table: movie_genres


Sample table: rating


Sample Solution:

SELECT mov_title, mov_year, rev_stars
FROM movie 
NATURAL JOIN movie_genres 
NATURAL JOIN genres 
NATURAL JOIN rating
WHERE gen_title = 'Mystery' AND rev_stars >= ALL (
SELECT rev_stars
FROM rating 
NATURAL JOIN movie_genres 
NATURAL JOIN genres
WHERE gen_title = 'Mystery');

Sample Output:

                     mov_title                      | mov_year | rev_stars
----------------------------------------------------+----------+-----------
 Vertigo                                            |     1958 |      8.40
(1 row)

Practice Online


Movie database model

Query Visualization:

Duration:

Query visualization of Find the highest-rated Mystery movie, and report the title, year, and rating - Duration

Rows:

Query visualization of Find the highest-rated Mystery movie, and report the title, year, and rating - Rows

Cost:

Query visualization of Find the highest-rated Mystery movie, and report the title, year, and rating - Cost

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

Previous: Write a query in SQL to find the highest-rated movie, and report its title, year, rating, and releasing country.
Next: Write a query in SQL to generate a report which shows the year when most of the Mystery movies produces, and number of movies and their average rating.

What is the difficulty level of this exercise?



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