SQLComparison Operators

Comparison Operators

Comparison operators are the building blocks of every WHERE condition. They compare a column (or expression) against a value and produce a true or false result for each row.
The standard operators

Operator

Meaning

=

Equal to

<>

Not equal to (the ANSI-standard form)

!=

Not equal to (widely supported, non-standard alias for <>)

<

Less than

>

Greater than

<=

Less than or equal to

>=

Greater than or equal to

<> vs !=
<> is the ANSI SQL standard way to say “not equal”. != is not part of the standard, but nearly every major database — PostgreSQL, MySQL, SQL Server, SQLite, Oracle — supports it as an alias. <> is the safer, maximally-portable choice; != is extremely common in practice and perfectly fine to use.
Comparing numbers

Numeric comparisons

SQL
SELECT product_name, price
FROM products
WHERE price &gt;= 100;
Comparing strings

Strings are compared lexicographically (roughly, dictionary order, character by character):

String comparison

SQL
SELECT last_name
FROM employees
WHERE last_name &lt; 'M';

This returns every employee whose last name sorts before the letter “M”.

Case sensitivity depends on collation
Whether 'apple' = 'Apple' evaluates to true depends on the database’s (or column’s) collation setting. Many databases default to case-insensitive comparison for text, while others — PostgreSQL notably — default to case-sensitive comparison unless you configure a case-insensitive collation. Always check your database’s defaults before relying on comparison behavior for text.
Comparing dates

Date comparison

SQL
SELECT order_id, order_date
FROM orders
WHERE order_date &gt;= '2024-01-01';
Dates compare chronologically — earlier dates are “less than” later ones — which makes range comparisons like this one read naturally. Be careful with date columns that also store a time component; we cover a related gotcha on the BETWEEN page.