SQL NOT EQUAL Operator

Last Updated : 16 Jun, 2026

The SQL NOT EQUAL operator compares two values and returns true if they are not equal. It’s used to filter out matching records in queries. If the values are equal, it returns false; if either value is NULL, it returns NULL.

Example: First, we create a demo SQL database and table, on which we will use the NOT EQUAL command.

Not-Equal

Query:

SELECT CustomerName, Country
FROM Customer
WHERE Country <> 'Japan';

Output:

country

Syntax:

SELECT * FROM table_name
WHERE column_name != value;

Examples of NOT EQUAL Operator

Let's look at some examples of the NOT EQUAL Operator in SQL and understand its working. First, we will create a demo SQL database and table on which we will use the NOT EQUAL operator.

geeksforgeeks

Example 1: SQL NOT EQUAL Operator For String

In this example, we display all those rows which do not have a name equal to 'Sofia'. We will use NOT EQUAL with WHERE clause in this case.

Query:

SELECT *
FROM students
WHERE name != 'Sofia';

Output:

g-output

Note: The NOT EQUAL comparison is case-sensitive for strings. Meaning "geeks" and "GEEKS" are two different strings for NOT EQUAL operator.

Example 2: SQL NOT EQUAL Operator with Multiple Condition

This query returns rows where the contest score is not 98, the rank is not 3 and the coding streak is at least 100, using the NOT operator with multiple conditions.

Query:

SELECT * 
FROM geeksforgeeks
WHERE contest_score != 98
AND rank != 3
AND coding_streak >= 100;

Output:

g-2

Example 3: SQL NOT EQUAL Operator with GROUP BY Clause

In this example, we display all those ranks with their count that do not have their contest score as 100 using GROUP BY clause. 

Query:

SELECT rank, COUNT(*) as count_score
FROM geeksforgeeks
WHERE contest_score != 100
GROUP BY rank;

Output:

Screenshot-2026-04-14-113651

Note: <> and != perform the same operation i.e. check inequality. The only difference between <> and != is that <> follows the ISO standard but != does not. So it is recommended to use <> for NOT EQUAL Operator.

Comment