MYSQL Tutorial



MySQL COMPARISON OPERATORS


MySQL Comparison Operators – Compare Values Like a Pro

Comparison operators in MySQL help you compare two values in WHERE clauses or conditions. They return TRUE or FALSE, letting you filter data precisely.

🔹 Common Comparison Operators

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')

🔹 Examples Using Comparison Operators

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');
  

🔹 Interactive Challenge

Write a query to find employees with salary > 55,000 and hired after 2019-01-01.

Click here for the answer
SELECT * FROM employees
WHERE salary > 55000 AND hire_date > '2019-01-01';
    

🔹 Summary

  • = 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.

🌟 Enjoyed Learning with Us?

Help others discover Technorank Learning by sharing your honest experience.
Your support inspires us to keep building!

Leave a Google Review