Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

SQL exercises on movie Database: Find the name of movie and director who directed a movie that casted a role as Sean Maguire

SQL movie Database: Join Exercise-4 with Solution

4. From the following tables, write a SQL query to find who directed a movie that casted a role as ‘Sean Maguire’. Return director first name, last name and movie title.

Sample table: director


Sample table: movie_direction


Sample table: movie_cast


Sample table: movie


Sample Solution:

SELECT dir_fname, dir_lname, mov_title
FROM  director 
JOIN movie_direction 
  ON director.dir_id=movie_direction.dir_id
JOIN movie 
  ON movie_direction.mov_id=movie.mov_id
JOIN movie_cast 
  ON movie_cast.mov_id=movie.mov_id
  WHERE role='Sean Maguire';

OR

SELECT dir_fname, dir_lname, mov_title
FROM  director, movie_direction, movie, movie_cast
WHERE director.dir_id=movie_direction.dir_id
AND movie_direction.mov_id=movie.mov_id
AND movie.mov_id=movie_cast.mov_id
AND movie_cast.role='Sean Maguire';

Sample Output:

      dir_fname       |      dir_lname       |                     mov_title
----------------------+----------------------+----------------------------------------------------
 Gus                  | Van Sant             | Good Will Hunting
(1 row)

Relational Algebra Expression:

Relational Algebra Expression: Find the name of movie and director who directed a movie that casted a role as Sean Maguire.

Relational Algebra Tree:

Relational Algebra Tree: Find the name of movie and director who directed a movie that casted a role as Sean Maguire.

Practice Online


Movie database model

Query Visualization for Sample Solution:

Duration:

Query visualization of Find the name of movie and director who directed a movie that casted a role as Sean Maguire - Duration

Rows:

Query visualization of Find the name of movie and director who directed a movie that casted a role as Sean Maguire - Rows

Cost:

Query visualization of Find the name of movie and director who directed a movie that casted a role as Sean Maguire - Cost

Query Visualization for alternate Sample Solution:

Duration:

Query visualization of Find the name of movie and director who directed a movie that casted a role as Sean Maguire - Duration

Rows:

Query visualization of Find the name of movie and director who directed a movie that casted a role as Sean Maguire - Rows

Cost:

Query visualization of Find the name of movie and director who directed a movie that casted a role as Sean Maguire - Cost

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

Previous: Write a query in SQL to find the name of movie and director (first and last names) who directed a movie that casted a role for 'Eyes Wide Shut'.
Next: From the following table, write a SQL query to find the actors who have not acted in any movie between1990 and 2000 (Begin and end values are included.). Return actor first name, last name, movie title and release year.

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