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 all the movies with title, year, date of release, duration, and name of the director which released before 1st January 1989, and sort the result in descending order on release date

SQL movie Database: Join Exercise-9 with Solution

9. From the following tables, write a SQL query to find the movies released before 1st January 1989. Sort the result-set in descending order by date of release. Return movie title, release year, date of release, duration, and first and last name of the director.

Sample table: movie


Sample table: director


Sample table: movie_direction


Sample Solution:

SELECT movie.mov_title, mov_year, mov_dt_rel,
       mov_time,dir_fname, dir_lname 
FROM movie
JOIN  movie_direction 
   ON movie.mov_id = movie_direction.mov_id
JOIN director 
   ON movie_direction.dir_id=director.dir_id
WHERE mov_dt_rel <'01/01/1989'
ORDER BY mov_dt_rel desc;

Sample Output:

                     mov_title                      | mov_year | mov_dt_rel | mov_time |      dir_fname       |      dir_lname
----------------------------------------------------+----------+------------+----------+----------------------+----------------------
 Aliens                                             |     1986 | 1986-08-29 |      137 | James                | Cameron
 Amadeus                                            |     1984 | 1985-01-07 |      160 | Milos                | Forman
 Deliverance                                        |     1972 | 1982-10-05 |      109 | John                 | Boorman
 Blade Runner                                       |     1982 | 1982-09-09 |      117 | Ridley               | Scott
 The Deer Hunter                                    |     1978 | 1979-03-08 |      183 | Michael              | Cimino
 Annie Hall                                         |     1977 | 1977-04-20 |       93 | Woody                | Allen
 Chinatown                                          |     1974 | 1974-08-09 |      130 | Roman                | Polanski
 Lawrence of Arabia                                 |     1962 | 1962-12-11 |      216 | David                | Lean
 The Innocents                                      |     1961 | 1962-02-19 |      100 | Jack                 | Clayton
 Vertigo                                            |     1958 | 1958-08-24 |      128 | Alfred               | Hitchcock
(10 rows)

Relational Algebra Expression:

Relational Algebra Expression: Find all the movies with title, year, date of release, duration, and name of the director which released before 1st January 1989, and sort the result in descending order on release date.

Relational Algebra Tree:

Relational Algebra Tree: Find all the movies with title, year, date of release, duration, and name of the director which released before 1st January 1989, and sort the result in descending order on release date.

Practice Online


Movie database model

Query Visualization:

Duration:

Query visualization of Find all the movies with title, year, date of release, duration, and name of the director which released before 1st January 1989, and sort the result in descending order on release date - Duration

Rows:

Query visualization of Find all the movies with title, year, date of release, duration, and name of the director which released before 1st January 1989, and sort the result in descending order on release date - Rows

Cost:

Query visualization of Find all the movies with title, year, date of release, duration, and name of the director which released before 1st January 1989, and sort the result in descending order on release date - 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 all the movies with year, genres, and name of the director.
Next: From the following tables, write a SQL query to compute the average time and count number of movies for each genre. Return genre title, average time and number of movies for each genre.

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