Home »
MySQL
MySQL NOT EQUAL TO (!=) Operator
MySQL | NOT EQUAL TO (!=) Operator: Learn about the MySQL NOT EQUAL TO Operator, with its explanation, syntax, and query examples.
Submitted by Apurva Mathur, on September 14, 2022
NOT EQUAL TO (!=) Operator
NOT EQUAL TO (!=) operator is used in the situation when you specifically don't want some condition as a result. In simple words, suppose you have three balls red, green, and blue and if I say I want the ball which is not equal to the red ball, that means the only possibility left is a green ball or blue ball. In the same way, in MySQL if you specifically don't want any particular condition you use this operator.
In MySQL when we want to use this operator we represent it in the following manner: != (press shift+1 and not operator sign will be displayed).
NOT EQUAL TO (!=) Operator Syntax
!=
Let us see some examples;
NOT EQUAL TO (!=) Operator Examples
Suppose we have a table named "student_details" and inside this table, we have the following columns,
And now suppose if, I want to know the details of the students from other departments except "CSE", then in such case, I will write,
SELECT * FROM student_details WHERE student_department != 'CSE';
As you can see, the result has all the names of the student from other departments except "CSE".
Now suppose I want to know the details of every department except "CSE" and "ME", in such case, we'll use two not operators and one and operator since we want to follow both the conditions.
SELECT * FROM student_details
WHERE student_department != 'CSE' AND student_department != 'ME';
As you can see the result has all the names from other departments except "CSE" and "ME".