SQL NOT EQUAL, written as <> or !=, returns rows where two expressions differ. Place it in a WHERE clause to filter out specific values across numeric, string, date, or boolean columns. <> is ANSI-standard; != also works in MySQL, PostgreSQL, SQL Server, and others. Avoid using NOT EQUAL against NULL—use IS NOT NULL or IS DISTINCT FROM instead.
SQL NOT EQUAL (<> or !=) returns rows where two expressions do not match. It works across numbers, text, dates, and booleans in all major databases.
SQL NOT EQUAL compares two expressions and returns TRUE when they differ. In a WHERE clause, it keeps only rows that fail to match the right-hand value.
ANSI SQL defines <> as the official NOT EQUAL operator. Most engines also accept !=. Use <> for maximum portability and != for readability if your database supports it.
Place <> or != between a column and a literal or expression: SELECT * FROM orders WHERE status <> 'shipped';
The query returns every order whose status is not "shipped."
Yes. SQL implicitly converts compatible types, so you can compare integers, decimals, strings, dates, and even booleans. Ensure both sides are compatible to avoid implicit-conversion performance hits.
NULL represents unknown, so any comparison with NULL yields UNKNOWN, not TRUE. WHERE column <> value
excludes NULL rows. Use WHERE column IS NOT NULL
or IS DISTINCT FROM
to include them intentionally.
Yes. Use AND, OR, and parentheses: WHERE region <> 'US' AND total > 1000
. Each operator evaluates separately, letting you build precise filters.
NOT EQUAL remains sargable—you can benefit from an index on the compared column. However, high selectivity matters; scanning may still be cheaper if most rows differ.
Text comparison follows the collation of your database. Case-insensitive collations treat 'ABC' and 'abc' as equal; case-sensitive ones do not. Specify the correct collation or use UPPER() functions.
Compare columns directly: WHERE start_date <> end_date
. Each row evaluates independently. Be cautious with NULLs; unknown values still return UNKNOWN.
IS DISTINCT FROM
treats NULL as a real value, returning TRUE when one side is NULL and the other is not. Use it when you must detect any difference, including NULL vs. non-NULL.
Logical equivalence lets you write NOT (column = value)
. This form clarifies intent in some ORMs but performs the same under the hood.
Common patterns include filtering out deprecated statuses, selecting non-US regions, finding rows where actual ≠ expected, and auditing data drift between two tables.
Absolutely. Parameterization avoids SQL injection and lets the query planner reuse execution plans: WHERE status <> :status_to_skip
.
MySQL, PostgreSQL, SQL Server, and SQLite accept !=. Oracle and Snowflake accept != but document <> as preferred. Stick to <> for vendor-neutral scripts.
If most rows differ, NOT EQUAL may return large result sets, making I/O the bottleneck. Add selective predicates or LIMIT clauses when possible.
Use ANSI-standard <>. Combine with IS NOT NULL when needed. Parameterize values. Watch collations. Prefer IS DISTINCT FROM for NULL-safe comparisons. Profile large scans.
NOT EQUAL removes matching rows, uses <> or !=, fails on NULL, and remains index-friendly. Mastering it helps craft precise filters and spot data mismatches quickly.
Yes. Compare text directly: WHERE name <> 'Alice'
. Collation determines case-sensitivity.
NOT EQUAL checks a single value, so it is usually faster than NOT IN, which builds a set. Performance depends on indexing and cardinality.
Use IS DISTINCT FROM
or combine WHERE column <> value OR column IS NULL
.
Use the equals operator (=) to match values or IS NULL
for NULL checks.