0% found this document useful (0 votes)
35 views3 pages

Multiple Table Test

The document provides instructions for creating and manipulating a Movies database, including the creation of movies and genres tables. It outlines specific SQL queries for data retrieval, filtering, aggregation, and sorting of movie records. The test concludes with tasks to execute SQL statements to verify their correctness.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views3 pages

Multiple Table Test

The document provides instructions for creating and manipulating a Movies database, including the creation of movies and genres tables. It outlines specific SQL queries for data retrieval, filtering, aggregation, and sorting of movie records. The test concludes with tasks to execute SQL statements to verify their correctness.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

SQL Test: Movies Database

Instructions:

1. Create the Movies database.


2. Use the database to create and manipulate the movies and genres tables.
3. Write SQL queries to perform the tasks described below.
4. Execute each query to verify its correctness.

Section 1: Database and Table Creation

1. Create Database:
Write an SQL statement to create a new database named Movies.
2. Switch Database:
Write an SQL statement to switch to the Movies database.
3. Create Movies Table:
Write an SQL statement to create a table named movies with the following columns:
○ movie_id (Primary Key, Integer)
○ movie_name (VARCHAR, 100 characters)
○ release_year (Integer)
○ genre_id (Foreign Key, Integer)
4. Create Genres Table:
Write an SQL statement to create a table named genres with the following columns:
○ genre_id (Primary Key, Integer)
○ genre_name (VARCHAR, 50 characters)
5. Insert Records into Genres Table:
Write SQL statements to insert the following records into the genres table:
genre_i genre_nam
d e

1 Action

2 Drama

3 Romance

4 Comedy

5 Thriller
6.
Insert Records into Movies Table:
Write SQL statements to insert the following records into the movies table:
movie_i movie_name release_yea genre_i
d r d

1 KGF 2018 1

2 Mungaru Male 2006 3

3 Googly 2013 4

4 Kirik Party 2016 4

5 Gaalipata 2008 1

6 Ugramm 2014 5

7 Thithi 2015 2

Section 2: Basic Data Retrieval

7. Select All Movies:


Write an SQL query to retrieve all records from the movies table.
8. Select Movies with Specific Columns:
Write an SQL query to retrieve only the movie_name and release_year columns from
the movies table.
9. Join Movies with Genres:
Write an SQL query to retrieve all movie names along with their respective genre names.

Section 3: Conditional Data Retrieval

10. Filter Movies by Release Year:


Write an SQL query to retrieve all movies released after 2010.
11. Filter Movies by Genre:
Write an SQL query to retrieve all movies that belong to the 'Romance' genre.
12. Filter Movies by Year and Genre:
Write an SQL query to retrieve all movies released between 2013 and 2018 and belong
to the 'Action' genre.

Section 4: Combined Conditions

13. Filter Movies by Multiple Genres:


Write an SQL query to retrieve all movies that belong to either the 'Drama' or 'Comedy'
genre.
14. Exclude Specific Movie Name:
Write an SQL query to retrieve all records where the movie_name is not 'KGF'.
15. Movies with Similar Names:
Write an SQL query to retrieve all movies where the movie_name starts with the letter
'G'.

Section 5: Aggregation and Grouping

16. Count Movies by Genre:


Write an SQL query to count the number of movies for each genre.
17. Average Release Year by Genre:
Write an SQL query to calculate the average release year for each genre.
18. Newest Movie in Each Genre:
Write an SQL query to retrieve the latest released movie for each genre.

Section 6: Sorting and Limiting Results

19. Sort Movies by Release Year:


Write an SQL query to retrieve all movies sorted by release_year in descending
order.
20. Limit Results to 3 Movies:
Write an SQL query to retrieve the first 3 records from the movies table.
21. Top 2 Movies by Genre:
Write an SQL query to retrieve the top 2 movies by release year for each genre.

End of Test

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy