DEV Community

Anjana R.K.
Anjana R.K.

Posted on

DB-TASK-Filtering Data

Hi everyone!
Find all movies where the special features are not listed (i.e.,special_features is NULL).
This query selects all movies where special_features column has no value (NULL).

SELECT * FROM film WHERE special_features IS NULL;

Find all movies where the rental duration is more than 7 days.
selects movies whose rental duration is greater than 7 days.

SELECT * FROM film WHERE rental_duration > 7;

Find all movies that have a rental rate of $4.99 and a replacement cost of more than $20.
this query selects movies that satisfy both rental_rate = 4.99 and replacement_cost greater than 20.

SELECT * FROM film WHERE rental_rate = 4.99 AND replacement_cost > 20;

Find all movies that have a rental rate of $0.99 or a rating of 'PG-13'.
this query selects movies that satisfy either rental_rate = 0.99 or rating = 'PG-13'.

SELECT * FROM film WHERE rental_rate = 0.99 OR rating = 'PG-13';

Retrieve the first 5 rows of movies sorted alphabetically by title.
this query selects first 5 movies sorted in alphabetical order using title.

SELECT * FROM film ORDER BY title ASC LIMIT 5;

Skip the first 10 rows and fetch the next 3 movies with the highest replacement cost.

SELECT * FROM film ORDER BY replacement_cost DESC LIMIT 3 OFFSET 10;

this query sorts movies by replacement_cost in descending order, skips first 10 rows and selects next 3.

Find all movies where the rating is either 'G', 'PG', or 'PG-13'.
this query selects movies whose rating is in the given list.

SELECT * FROM film WHERE rating IN ('G','PG','PG-13');

Find all movies with a rental rate between $2 and $4.
this query selects movies whose rental rate is between 2 and 4.

SELECT * FROM film WHERE rental_rate BETWEEN 2 AND 4;

Find all movies with titles that start with 'The'.
this query selects movies whose title starts with "The".

SELECT * FROM film WHERE title LIKE 'The%';

Find the first 10 movies with a rental rate of $2.99 or $4.99, a rating of 'R', and a title containing the word "Love".
here it selects from movies that satisfies all conditions and limits result to 10.

SELECT * FROM film WHERE rental_rate IN (2.99,4.99) AND rating = 'R' AND title LIKE '%Love%' LIMIT 10;

Find all movies where the title contains the % symbol.
this query selects movies where title contains % symbol using escape.

SELECT * FROM film WHERE title LIKE '%\%%' ESCAPE '\';

Find all movies where the title contains an underscore (_).
SELECTS movies where title contains underscore character .

SELECT * FROM film WHERE title LIKE '%_%' ESCAPE '\';

Find all movies where the title starts with "A" or "B" and ends with "s".
The query selects movies that start with Aor B and end with s.

SELECT * FROM film WHERE (title LIKE 'A%' OR title LIKE 'B%') AND title LIKE '%s';

Find all movies where the title contains "Man","Men", or"Woman".
This query selects movies whose title contains given words.

SELECT * FROM film WHERE title LIKE '%Man%' OR title LIKE '%Men%' OR title LIKE '%Woman%';

Find all movies with titles that contain digits (e.g.,"007", "2", "300").
this query selects movies whose title contains numbers.

SELECT * FROM film WHERE title REGEXP '[0-9]';

Find all movies with titles containing a backslash().
this query selects movies whose title contains backslash symbol.

SELECT * FROM film WHERE title LIKE '%\%';

Find all movies where the title does contain the words "Love" or "Hate".
this selects movies containing either Love or Hate in title.

SELECT * FROM film WHERE title LIKE '%Love%' OR title LIKE '%Hate%';

Find the first 5 movies with titles that end with "er", "or",or "ar".

SELECT * FROM film WHERE title LIKE '%er' OR title LIKE '%or' OR title LIKE '%ar' LIMIT 5;

here it selects movies ending with given patterns and limits to 5.

Top comments (0)