Comparison Operators in SQL
? Comparison Operators in SQL
Comparison operators are used in SQL to compare two expressions and return a Boolean result (TRUE, FALSE, or UNKNOWN). They are commonly used in WHERE clauses to filter data.
? Common Comparison Operators
| Operator | Description | Example | Result |
|---|---|---|---|
= | Equal to | age = 30 | True if age is exactly 30 |
<> or != | Not equal to | status <> 'active' | True if status is not 'active' |
> | Greater than | salary > 50000 | True if salary is greater than 50000 |
< | Less than | age < 65 | True if age is less than 65 |
>= | Greater than or equal to | score >= 75 | True if score is 75 or more |
<= | Less than or equal to | date <= '2025-12-31' | True if date is on or before Dec 31, 2025 |
? Example Usage
SELECT * FROM employeesWHERE salary >= 60000 AND age < 50 AND department <> 'HR';? Notes
<>and!=both mean not equal; support may vary by SQL dialect.When comparing with
NULL, useIS NULLorIS NOT NULLinstead of= NULL.Comparison operators can be combined with logical operators (
AND,OR,NOT) for complex conditions.
If you want, I can explain how comparison operators work with NULL or show examples in specific databases!