
192 views
MySQL Not Equal
The MySQL Not Equal operator is used to compare values and check if they are not equal to each other. The “Not Equal” operator is represented by <>
or !=
. It returns TRUE
if the values on the left and right sides of the operator are not equal and FALSE
if they are equal.
Here’s the basic syntax for using the “Not Equal” operator:
value1 <> value2
or
value1 != value2
Here’s how it works:
value1
andvalue2
are the values you want to compare.- If
value1
is not equal tovalue2
, the expression evaluates toTRUE
. - If
value1
is equal tovalue2
, the expression evaluates toFALSE
.
Here are some examples to illustrate the use of the “Not Equal” operator:
- Match all records where the
category
is not equal to “Electronics”:
SELECT *
FROM products
WHERE category <> 'Electronics';
or
SELECT *
FROM products
WHERE category != 'Electronics';
- Retrieve customers who do not have a specific email address:
SELECT *
FROM customers
WHERE email != '[email protected]';
- Find employees whose salary is not equal to a specific value:
SELECT *
FROM employees
WHERE salary <> 50000;
The “Not Equal” operator is useful when you want to filter rows based on values that are different from a specific value or set of values. It allows you to exclude rows that meet certain conditions from your SQL query results.