SQL exercises on movie Database: Find the director's first and last name together with the title of the movie(s) they directed and received the rating
SQL movie Database: Join Exercise-15 with Solution
15. From the following tables, write a SQL query to find those movies, which have received ratings. Return movie title, director first name, director last name and review stars.
Sample table: movie
Sample table: rating
p>Sample table: movie_direction
Sample table: director
Sample Solution:
SELECT mov_title, dir_fname,dir_lname, rev_stars
FROM Movie
JOIN movie_direction USING(mov_id)
join director using (dir_id)
left join rating using(mov_id)
where rev_stars is not null;
Sample Output:
mov_title | dir_fname | dir_lname | rev_stars ----------------------------------------------------+----------------------+----------------------+----------- Vertigo | Alfred | Hitchcock | 8.40 The Innocents | Jack | Clayton | 7.90 Lawrence of Arabia | David | Lean | 8.30 Blade Runner | Ridley | Scott | 8.20 The Usual Suspects | Bryan | Singer | 8.60 Boogie Nights | Paul | Thomas Anderson | 3.00 Annie Hall | Woody | Allen | 8.10 Princess Mononoke | Hayao | Miyazaki | 8.40 American Beauty | Sam | Mendes | 7.00 Titanic | James | Cameron | 7.70 Good Will Hunting | Gus | Van Sant | 4.00 Donnie Darko | Richard | Kelly | 8.10 Slumdog Millionaire | Danny | Boyle | 8.00 Aliens | James | Cameron | 8.40 Beyond the Sea | Kevin | Spacey | 6.70 (15 rows)
Practice Online
Query Visualization:
Duration:
Rows:
Cost:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: From the following tables, write a SQL query to find those movies that have at least one rating and received highest number of stars. Sort the result-set on movie title. Return movie title and maximum review stars.
Next: Write a query in SQL to find the movie title, actor first and last name, and the role for those movies where one or more actors acted in two or more movies.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
SQL: Tips of the Day
SQL Server SELECT into existing table.
INSERT INTO dbo.TABLETWO SELECT col1, col2 FROM dbo.TABLEONE WHERE col3 LIKE @search_key
This assumes there's only two columns in dbo.TABLETWO - you need to specify the columns otherwise:
INSERT INTO dbo.TABLETWO (col1, col2) SELECT col1, col2 FROM dbo.TABLEONE WHERE col3 LIKE @search_key
Database: SQL Server
Ref: https://bit.ly/3y6tpA3
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework