In SQL, the NOT EQUAL operator is used to filter records that do not match a specified value. There are two common ways to express the “not equal” condition in SQL:
!=
: This is the most commonly used operator for “not equal” in many SQL dialects (e.g., MySQL, SQL Server, PostgreSQL).<>
: This is the standard SQL operator for “not equal” and works across almost all SQL databases.
Example:
If you want to select all records from a students
table where the age
is not equal to 18, you can write the query like this:
SELECT * FROM students
WHERE age != 18;
or using <>
:
SELECT * FROM students
WHERE age <> 18;
Both queries will return rows where the age
is not 18.