Filtering a DB using SQL Queries

Published: (March 29, 2026 at 06:40 AM EDT)
2 min read
Source: Dev.to

Source: Dev.to

SQL Query Examples

#DescriptionQuery
1Movies with rental rate > $3SELECT * FROM film WHERE rental_rate > 3;
2Rental rate > $3 and replacement cost  3 AND replacement_cost 20SELECT * FROM film WHERE rental_rate = 4.99 AND replacement_cost > 20;
19Movies with rental rate = 0.99 or rating ‘PG-13’SELECT * FROM film WHERE rental_rate = 0.99 OR rating = 'PG-13';
20Movies with rating in (‘G’, ‘PG’, ‘PG-13’)SELECT * FROM film WHERE rating IN ('G', 'PG', 'PG-13');
21Movies with rental rate between $2 and $4SELECT * FROM film WHERE rental_rate BETWEEN 2 AND 4;
22Movies where special_features is NULLSELECT * FROM film WHERE special_features IS NULL;
23Customers without an email addressSELECT * FROM customer WHERE email IS NULL;
24Movies with rental duration > 7 daysSELECT * FROM film WHERE rental_duration > 7;
25Movies with rental rate = 2.99 or 4.99, rating ‘R’, title contains “Love” (top 10)SELECT * FROM film WHERE rental_rate IN (2.99, 4.99) AND rating = 'R' AND title LIKE '%Love%' LIMIT 10;
26Titles containing the % symbolSELECT * FROM film WHERE title LIKE '%\%%' ESCAPE '\';
27Titles containing the underscore _SELECT * FROM film WHERE title LIKE '%\_%' ESCAPE '\';
28Titles containing digitsSELECT * FROM film WHERE title REGEXP '[0-9]';
29Titles containing a backslash (\)SELECT * FROM film WHERE title LIKE '%\\\\%';
3010 customers after skipping the first 20, sorted by last nameSELECT * FROM customer ORDER BY last_name ASC LIMIT 10 OFFSET 20;

What I Learned

  • Filtering data with WHERE, AND, OR, IN, BETWEEN, and IS NULL.
  • Sorting results using ORDER BY.
  • Pagination (page navigation) with LIMIT and OFFSET.
  • Pattern matching with LIKE (including escape characters) and regular expressions (REGEXP).

Pattern matching with LIKE and REGEXP

Handling missing data using NULL

0 views
Back to Blog

Related posts

Read more »

32 - Filter Assignments

SQL Queries for the film Table Movies where special_features is NULL sql SELECT FROM film WHERE special_features IS NULL; Movies where rental duration > 7 days...

Database- Querying and Filtering Data

Tasks 1. Retrieve film titles and their rental rates Alias title as Movie Title and rental_rate as Rate. sql SELECT title AS 'Movie Title', rental_rate AS 'Rat...

Basic Select SQL Queries

'HackerRank SQL Practice Question 1 Task: Query all columns for a city in CITY with the ID 1661. Solution: sql SELECT FROM CITY WHERE ID = 1661;

CA 40 - Alter Tables

Practice ALTER TABLE Statements 1. Make Email NOT NULL customers sql ALTER TABLE customers MODIFY email VARCHAR100 NOT NULL; Result: email becomes a required f...