Not Boring Movies - Problem

Given a table Cinema that contains information about movies including their ID, name, description, and rating.

Write a SQL query to find all movies that meet both of these criteria:

  • The movie has an odd-numbered ID
  • The movie's description is not "boring"

Return the results ordered by rating in descending order.

Table Schema

Cinema
Column Name Type Description
id PK int Primary key - unique movie identifier
movie varchar Name of the movie
description varchar Genre or description of the movie
rating float Movie rating between 0.00 and 10.00
Primary Key: id
Note: Each row represents a movie with its details and rating

Input & Output

Example 1 — Mixed Movies
Input Table:
id movie description rating
1 War great 3D 8.9
2 Science fiction 8.5
3 irish boring 6.2
4 Ice song Fantacy 8.6
5 House card Interesting 9.1
Output:
id movie description rating
5 House card Interesting 9.1
1 War great 3D 8.9
💡 Note:

Movies with IDs 1 and 5 have odd IDs and descriptions that are not 'boring'. ID 2 and 4 are even (excluded), ID 3 has 'boring' description (excluded). Results are sorted by rating descending: 9.1, then 8.9.

Example 2 — All Boring or Even IDs
Input Table:
id movie description rating
2 Action thrilling 7.5
4 Comedy funny 8
7 Drama boring 9.5
Output:
id movie description rating
💡 Note:

No movies meet both criteria. IDs 2 and 4 are even numbers (excluded), and ID 7 has 'boring' description (excluded). Result is empty.

Example 3 — Single Valid Movie
Input Table:
id movie description rating
9 Thriller suspense 7.8
Output:
id movie description rating
9 Thriller suspense 7.8
💡 Note:

Movie with ID 9 has an odd ID and description is not 'boring', so it's included in the result.

Constraints

  • 1 ≤ id ≤ 1000
  • rating is a float with 2 decimal places in range [0, 10]
  • movie and description are varchar strings

Visualization

Tap to expand
Not Boring Movies INPUT: Movies Table id name desc rating 1 War great 8.9 2 Science boring 8.5 3 Irish boring 6.2 4 Ice fantasy 8.6 5 House comedy 9.1 = Even ID (excluded) = Odd ID (candidate) boring = Excluded description Filter Conditions: id % 2 = 1 (odd) description != 'boring' ALGORITHM STEPS 1 Filter Odd IDs WHERE id % 2 = 1 id=1 (War) OK id=3 (Irish), id=5 (House) OK 2 Exclude 'boring' description != 'boring' id=1 (great) OK id=3 (boring) SKIP id=5 OK 3 Sort by Rating ORDER BY rating DESC 9.1 (House) --> 8.9 (War) 4 Return Results SELECT * FROM cinema WHERE id%2=1 AND desc!='boring' FINAL RESULT id name desc rating 5 House comedy 9.1 1 War great 8.9 2 Movies Found! Criteria Met: * Odd IDs: 1, 5 * Not boring: great, comedy * Sorted: 9.1 then 8.9 Query Complete 5 rows scanned 2 rows returned Key Insight: The modulo operator (id % 2 = 1) efficiently filters odd IDs. Combined with a string comparison (description != 'boring'), this creates an optimal single-pass query. ORDER BY DESC ensures highest ratings first. TutorialsPoint - Not Boring Movies | Optimal Solution
Asked in
Amazon 23 Google 18 Microsoft 15
28.5K Views
High Frequency
~8 min Avg. Time
892 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen