Open In App

SQL NOT EQUAL Operator

Last Updated : 17 Nov, 2025
Comments
Improve
Suggest changes
3 Likes
Like
Report

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.

  • It is used in the WHERE clause to filter records.
  • It works with numbers and strings.

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 'Harsh'. 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

In this example, we display all those rows which do not have their contest score as 98 and rank as 3 and the coding streak should be greater than or equal to 100. Using AND or OR operator you can use the SQL NOT operator for multiple values.

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:

g-3

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.


Explore