6
deck
1. Why Use Comparison Operators?
Comparison operators help you filter rows by comparing values.
They let you:
- Show only students who passed
- Get products under a certain price
- Filter by date ranges or categories
They’re essential for building powerful SQL queries.
===
2. Common Operators Overview
Operator | Meaning | Example |
---|---|---|
= | Equal to | grade = 90 |
!= | Not equal to | grade != 100 |
> | Greater than | grade > 85 |
< | Less than | grade < 70 |
>= | Greater than or equal to | grade >= 80 |
<= | Less than or equal to | grade <= 60 |
BETWEEN | Between two values | grade BETWEEN 80 AND 90 |
These are used inside the WHERE
clause.
===
3. Example: Filtering Movie Ratings
A streaming app wants to show only top-rated movies:
SELECT title, rating
FROM movies
WHERE rating > 4.5;
This query displays only movies with a rating above 4.5.
===
4. Visualizing BETWEEN
BETWEEN
includes both boundary values.
BETWEEN 80 AND 90
= includes 80, 81, ..., 89, 90
It's useful for filtering within a specific numeric range.
===
5. Comparing Text
Comparison operators also work with strings.
SELECT name
FROM students
WHERE name = 'Alice';
You can compare names, categories, and other text values — just remember to use quotes (''
).
Want to learn more?
Join CodeFriends Plus membership or enroll in a course to start your journey.