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
| # | Description | Query |
|---|---|---|
| 1 | Movies with rental rate > $3 | SELECT * FROM film WHERE rental_rate > 3; |
| 2 | Rental rate > $3 and replacement cost 3 AND replacement_cost 20 | SELECT * FROM film WHERE rental_rate = 4.99 AND replacement_cost > 20; |
| 19 | Movies with rental rate = 0.99 or rating ‘PG-13’ | SELECT * FROM film WHERE rental_rate = 0.99 OR rating = 'PG-13'; |
| 20 | Movies with rating in (‘G’, ‘PG’, ‘PG-13’) | SELECT * FROM film WHERE rating IN ('G', 'PG', 'PG-13'); |
| 21 | Movies with rental rate between $2 and $4 | SELECT * FROM film WHERE rental_rate BETWEEN 2 AND 4; |
| 22 | Movies where special_features is NULL | SELECT * FROM film WHERE special_features IS NULL; |
| 23 | Customers without an email address | SELECT * FROM customer WHERE email IS NULL; |
| 24 | Movies with rental duration > 7 days | SELECT * FROM film WHERE rental_duration > 7; |
| 25 | Movies 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; |
| 26 | Titles containing the % symbol | SELECT * FROM film WHERE title LIKE '%\%%' ESCAPE '\'; |
| 27 | Titles containing the underscore _ | SELECT * FROM film WHERE title LIKE '%\_%' ESCAPE '\'; |
| 28 | Titles containing digits | SELECT * FROM film WHERE title REGEXP '[0-9]'; |
| 29 | Titles containing a backslash (\) | SELECT * FROM film WHERE title LIKE '%\\\\%'; |
| 30 | 10 customers after skipping the first 20, sorted by last name | SELECT * FROM customer ORDER BY last_name ASC LIMIT 10 OFFSET 20; |
What I Learned
- Filtering data with
WHERE,AND,OR,IN,BETWEEN, andIS NULL. - Sorting results using
ORDER BY. - Pagination (page navigation) with
LIMITandOFFSET. - Pattern matching with
LIKE(including escape characters) and regular expressions (REGEXP).