- Movies where special_features is NULL
SELECT *
FROM film
WHERE special_features IS NULL;
Explanation:
Here I am checking for NULL values.
We cannot use = for NULL, so I used IS NULL.
- Rental duration more than 7 days
SELECT *
FROM film
WHERE rental_duration > 7;
Explanation:
Filtered movies where rental duration is greater than 7.
- Rental rate = 4.99 and replacement cost > 20
SELECT *
FROM film
WHERE rental_rate = 4.99
AND replacement_cost > 20;
Explanation:
Used AND because both conditions must be true.
- Rental rate = 0.99 OR rating = 'PG-13'
SELECT *
FROM film
WHERE rental_rate = 0.99
OR rating = 'PG-13';
Explanation:
Used OR because any one condition is enough.
- First 5 movies sorted by title
SELECT *
FROM film
ORDER BY title
LIMIT 5;
Explanation:
Sorted by title and took first 5 rows.
- Skip 10 rows, next 3 highest replacement cost
SELECT *
FROM film
ORDER BY replacement_cost DESC
OFFSET 10
LIMIT 3;
Explanation:
Sorted by highest cost, skipped first 10, then took next 3.
- Rating is G, PG, or PG-13
SELECT *
FROM film
WHERE rating IN ('G', 'PG', 'PG-13');
Explanation:
Used IN instead of multiple OR conditions.
- Rental rate between 2 and 4
SELECT *
FROM film
WHERE rental_rate BETWEEN 2 AND 4;
Explanation:
Used BETWEEN for range values.
- Titles start with 'The'
SELECT *
FROM film
WHERE title LIKE 'The%';
Explanation:
% means anything after "The".
- First 10 movies with multiple conditions
SELECT *
FROM film
WHERE rental_rate IN (2.99, 4.99)
AND rating = 'R'
AND title LIKE '%Love%'
LIMIT 10;
Explanation:
Combined multiple filters and limited result.
- Titles containing %
SELECT *
FROM film
WHERE title LIKE '%\%%' ESCAPE '\';
Explanation:
Used escape character to search actual % symbol.
- Titles containing underscore (_)
SELECT *
FROM film
WHERE title LIKE '%_%' ESCAPE '\';
Explanation:
_ is special, so escaped it using .
- Titles start with A or B and end with s
SELECT *
FROM film
WHERE (title LIKE 'A%' OR title LIKE 'B%')
AND title LIKE '%s';
Explanation:
Combined start and end conditions.
- Titles with Man, Men, or Woman
SELECT *
FROM film
WHERE title LIKE '%Man%'
OR title LIKE '%Men%'
OR title LIKE '%Woman%';
Explanation:
Checked multiple words using OR.
- Titles containing digits
SELECT *
FROM film
WHERE title ~ '[0-9]';
Explanation:
Used regex to find numbers in title.
- Titles containing backslash ()
SELECT *
FROM film
WHERE title LIKE '%\%';
Explanation:
Used double backslash to match single backslash.
- Titles containing Love or Hate
SELECT *
FROM film
WHERE title LIKE '%Love%'
OR title LIKE '%Hate%';
Explanation:
Filtered titles containing specific words.
- First 5 movies ending with er, or, ar
SELECT *
FROM film
WHERE title LIKE '%er'
OR title LIKE '%or'
OR title LIKE '%ar'
LIMIT 5;
Explanation:
Checked ending patterns and limited to 5 rows.
Top comments (0)