Not Equal in MySQL
Robert Cooper
Robert Cooper Senior Engineer at Basedash
· January 31, 2025
Robert Cooper
Robert Cooper Senior Engineer at Basedash
· January 31, 2025
The ‘not equal’ operator is a solid way to compare data. This post covers how to use it.
The ‘not equal’ operator in MySQL is represented by <> or !=. It’s used in a WHERE clause to filter records where the specified column’s value is not equal to a given value.
SELECT * FROM table_name WHERE column_name <> value;
Or alternatively:
SELECT * FROM table_name WHERE column_name != value;
To exclude records with a specific value, use the ‘not equal’ operator in the WHERE clause.
SELECT * FROM users WHERE status <> 'inactive';
‘Not equal’ can be combined with other conditions using AND or OR.
SELECT * FROM products WHERE price <> 100 AND category = 'electronics';
Remember, NULL values require the IS NOT NULL operator instead of ‘not equal’.
SELECT * FROM employees WHERE last_name IS NOT NULL;
While = checks for equality, <> or != checks for inequality.
To find rows that do not match a specific pattern, combine ‘not equal’ with NOT LIKE.
SELECT * FROM books WHERE title NOT LIKE '%cookbook%';
<> and != are functionally identical, but some databases only support one.NULL values requires special attention (see above).Consider a database of a bookstore. To find all books that are not in the ‘Fiction’ category and cost more than $20, use:
SELECT * FROM books WHERE category != 'Fiction' AND price > 20;
If this query pattern is part of recurring reporting, Basedash helps you turn it into reusable, AI-native BI workflows: prompt-to-SQL, shared dashboards, and trusted answers that stay aligned with your data model.
Written by
Senior Engineer at Basedash
Robert Cooper is a senior engineer at Basedash who builds full-stack product systems across SQL data infrastructure, APIs, and frontend architecture. His work focuses on application performance, developer velocity, and reliable self-hosted workflows that make data operations easier for teams at scale.
Basedash lets you build charts, dashboards, and reports in seconds using all your data.