Skip to content
Exercises · Q3
Q.

Consider the following MOVIE table and write the SQL queries based on it.

MovieIDMovieNameCategoryReleaseDateProductionCostBusinessCost
001Hindi_MovieMusical2018-04-23124500130000
002Tamil_MovieAction2016-05-17112000118000
003English_MovieHorror2017-08-06245000360000
004Bengali_MovieAdventure2017-01-0472000100000
005Telugu_MovieAction-100000-
006Punjabi_MovieComedy-30500-

a) Display all the information from the Movie table.

b) List business done by the movies showing only MovieID, MovieName and Total_Earning. Total_Earning to be calculated as the sum of ProductionCost and BusinessCost.

c) List the different categories of movies.

d) Find the net profit of each movie showing its MovieID, MovieName and NetProfit. Net Profit is to be calculated as the difference between Business Cost and Production Cost.

e) List MovieID, MovieName and Cost for all movies with ProductionCost greater than 10,000 and less than 1,00,000.

f) List details of all movies which fall in the category of comedy or action.

g) List details of all movies which have not been released yet.

Rajasthan RbseTextbookSubjective· 4mImportance★★★★★
45% · 43/95 Questions
✓ Free question

This question tests your ability to write basic SQL queries — SELECT, calculated columns, WHERE with AND/OR, IS NULL, and DISTINCT — using a given MOVIE table. Each sub-part targets a specific SQL clause or operator.

This is a query task with multiple sub-parts (a) through (g). I will answer each sub-part in order, providing the SQL query and a brief explanation of the key clause or logic used.

Watch out

Notice that some rows have NULL values (shown as - in the table) for ReleaseDate and BusinessCost. In SQL, NULL is not equal to anything, not even another NULL. So when checking for "not released yet", you must use IS NULL, not = NULL.


(a) Display all the information from the Movie table.

SELECT * FROM Movie;

This is the simplest query — SELECT * retrieves every column and every row from the table. The * is a wildcard meaning "all columns".


(b) List business done by the movies showing only MovieID, MovieName and Total_Earning. Total_Earning to be calculated as the sum of ProductionCost and BusinessCost.

SELECT MovieID, MovieName, ProductionCost + BusinessCost AS Total_Earning
FROM Movie;

The key idea here is a calculated column. You can perform arithmetic directly in the SELECT clause. The AS keyword gives a name to the result column. Note that if either ProductionCost or BusinessCost is NULL, the sum will also be NULL — that's correct behaviour for the given data (Movie 005 and 006 have no BusinessCost, so their Total_Earning will be NULL).


(c) List the different categories of movies.

SELECT DISTINCT Category FROM Movie;

DISTINCT eliminates duplicate rows from the result. Without it, you'd get every category for every movie, including repeats. With DISTINCT, you get each category only once.


(d) Find the net profit of each movie showing its MovieID, MovieName and NetProfit. Net Profit is to be calculated as the difference between Business Cost and Production Cost.

SELECT MovieID, MovieName, BusinessCost - ProductionCost AS NetProfit
FROM Movie;

Again, a calculated column. The order matters: BusinessCost - ProductionCost gives profit (positive if the movie earned more than it cost to produce). For movies with NULL in either column, the result will be NULL.


(e) List MovieID, MovieName and Cost for all movies with ProductionCost greater than 10,000 and less than 1,00,000.

SELECT MovieID, MovieName, ProductionCost AS Cost
FROM Movie
WHERE ProductionCost > 10000 AND ProductionCost < 100000;

The WHERE clause filters rows. The condition uses AND to combine two comparisons. Note that the column alias Cost is given to ProductionCost in the output. The values 10,000 and 1,00,000 are written without commas in SQL (commas are not allowed in numeric literals).

Tip

You could also write WHERE ProductionCost BETWEEN 10001 AND 99999 to get the same result, but BETWEEN is inclusive, so you'd need to adjust the boundaries. The > and < approach is clearer for strict inequalities.


(f) List details of all movies which fall in the category of comedy or action.

SELECT * FROM Movie
WHERE Category = 'Comedy' OR Category = 'Action';

The OR operator includes rows that satisfy either condition. String comparisons in SQL are case-sensitive by default in many systems (though MySQL is case-insensitive by default). The values in the table are 'Comedy' and 'Action' with capital first letters, so the query matches exactly.


(g) List details of all movies which have not been released yet.

SELECT * FROM Movie
WHERE ReleaseDate IS NULL;

This is the critical one. The table shows - for ReleaseDate for movies 005 and 006, which in SQL means NULL. You cannot write WHERE ReleaseDate = NULL — that will never be true because NULL is not equal to anything. The correct operator is IS NULL.

Watch out

A common mistake is to write WHERE ReleaseDate = NULL. In SQL, NULL = NULL evaluates to UNKNOWN, not TRUE, so the condition never matches any row. Always use IS NULL or IS NOT NULL.


✓Final answer

The queries are as given above. For the given data:

  • (a) returns all 6 rows.
  • (b) returns 6 rows; Movie 005 and 006 have NULL for Total_Earning.
  • (c) returns 5 distinct categories: Musical, Action, Horror, Adventure, Comedy.
  • (d) returns 6 rows; Movie 005 and 006 have NULL for NetProfit.
  • (e) returns MovieID 004 (Bengali_Movie, 72000) and 006 (Punjabi_Movie, 30500).
  • (f) returns MovieID 002 (Tamil_Movie, Action), 005 (Telugu_Movie, Action), and 006 (Punjabi_Movie, Comedy).
  • (g) returns MovieID 005 (Telugu_Movie) and 006 (Punjabi_Movie).

Unlock everything free for 14 days

  • Full step-by-step solutions
  • Concept-first explanations
  • Methods, shortcuts & mistakes
  • PYQ mapping + timed mock tests

Full access for 14 days. No credit card required.