Comparison operators in MySQL help you compare two values in WHERE clauses or conditions. They return TRUE or FALSE, letting you filter data precisely.
| Operator | Meaning | Example |
|---|---|---|
= |
Equal to | salary = 50000 |
<> or != |
Not equal to | department <> 'Sales' |
< |
Less than | hire_date < '2020-01-01' |
<= |
Less than or equal to | salary <= 60000 |
> |
Greater than | salary > 55000 |
>= |
Greater than or equal to | hire_date >= '2019-01-01' |
BETWEEN ... AND ... |
Between two values (inclusive) | salary BETWEEN 50000 AND 60000 |
LIKE |
Matches a pattern (wildcards % and _) |
first_name LIKE 'J%' |
IN |
Value is in a list | department IN ('Sales', 'IT') |
1. Find employees hired before 2020:
SELECT * FROM employees WHERE hire_date < '2020-01-01';
2. Find employees with salary between 50,000 and 60,000:
SELECT * FROM employees WHERE salary BETWEEN 50000 AND 60000;
3. Find employees whose first name starts with 'J':
SELECT * FROM employees WHERE first_name LIKE 'J%';
4. Find employees in Sales or IT departments:
SELECT * FROM employees
WHERE department IN ('Sales', 'IT');
Write a query to find employees with salary > 55,000 and hired after 2019-01-01.
SELECT * FROM employees
WHERE salary > 55000 AND hire_date > '2019-01-01';
= and <> / != for equal and not equal.<, <=, >, >= for numeric or date comparisons.BETWEEN ... AND ... for ranges.LIKE for pattern matching with wildcards.IN to check if a value matches any value in a list.Help others discover Technorank Learning by sharing your honest experience.
Your support inspires us to keep building!