Sub queries Related Exercise
Note: Apply all queries using SQL server.
Sample Database:
Sample table: actor
act_id | act_fname | act_lname | act_gender
--------+----------------------+----------------------+------------
101 | James | Stewart | M
102 | Deborah | Kerr | F
103 | Peter | OToole | M
104 | Robert | De Niro | M
105 | F. Murray | Abraham | M
106 | Harrison | Ford | M
107 | Nicole | Kidman | F
108 | Stephen | Baldwin | M
109 | Jack | Nicholson | M
110 | Mark | Wahlberg | M
Sample table: movie_cast
act_id | mov_id | role
--------+--------+--------------------------------
101 | 901 | John Scottie Ferguson
102 | 902 | Miss Giddens
103 | 903 | T.E. Lawrence
104 | 904 | Michael
105 | 905 | Antonio Salieri
106 | 906 | Rick Deckard
Sample table: movie
mov_id mov_title mov_year mov_time mov_lang mov_dt_rel mov_rel_country
901 Vertigo 1958 128 English 8/24/1958 UK
902 The Innocents 1961 100 English 2/19/1962 SW
903 Lawrence of Arabia 1962 216 English 12/11/1962 UK
904 The Deer Hunter 1978 183 English 3/8/1979 UK
905 Amadeus 1984 160 English 1/7/1985 UK
906 Blade Runner 1982 117 English 9/9/1982 UK
907 Eyes Wide Shut 1999 159 English UK
908 The Usual Suspects 1995 106 English 8/25/1995 UK
Sample table: director
dir_id | dir_fname | dir_lname
--------+----------------------+----------------------
201 | Alfred | Hitchcock
202 | Jack | Clayton
203 | David | Lean
204 | Michael | Cimino
205 | Milos | Forman
206 | Ridley | Scott
207 | Stanley | Kubrick
Sample table: movie_direction
dir_id | mov_id
--------+--------
201 | 901
202 | 902
203 | 903
204 | 904
205 | 905
206 | 906
207 | 907
208 | 908
Sample table: movie_cast
act_id | mov_id | role
--------+--------+--------------------------------
101 | 901 | John Scottie Ferguson
102 | 902 | Miss Giddens
103 | 903 | T.E. Lawrence
104 | 904 | Michael
105 | 905 | Antonio Salieri
106 | 906 | Rick Deckard
107 | 907 | Alice Harford
108 | 908 | McManus
Sample table: reviewer
rev_id | rev_name
--------+--------------------------------
9001 | Righty Sock
9002 | Jack Malvern
9003 | Flagrant Baronessa
9004 | Alec Shaw
9005 |
9006 | Victor Woeltjen
9007 | Simon Wright
9008 | Neal Wruck
9009 | Paul Monks
9010 | Mike Salvati
Etc
Tasks:
1 .Write a query in SQL to list all the information of the actors who played a role in
the movie 'Annie Hall'.
2. Write a query in SQL to find the name of the director (first and last names) who
directed a movie that casted a role for 'Eyes Wide Shut'. (using sub query)
3. Write a query in SQL to list all the movies which released in the country other
than UK.
4. Write a query in SQL to find the movie title, year, date of release, director and
actor for those movies which reviewer is unknown.
5. Write a query in SQL to find the titles of all movies directed by the director whose
first and last name are Woddy Allen.
6-Write a query in SQL to find all the years which produced at least one movie and
that received a rating of more than 3 stars. Show the results in increasing order.
7-Write a query in SQL to find the titles of all movies that have no ratings.
8. Write a query in SQL to find the names of all reviewers who have ratings with a
NULL value.
9. Write a query in SQL to return the reviewer name, movie title, and stars for those
movies which reviewed by a reviewer and must be rated. Sort the result by reviewer
name, movie title, and number of stars.
10. Write a query in SQL to find the reviewer's name and the title of the movie for
those reviewers who rated more than one movies.
Reference (Link for helping)
https://www.w3resource.com/sql-exercises/movie-database-
exercise/subqueries-exercises-on-movie-database.php