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,

NOT EQUAL TO (!=) Operator Example 1

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';
NOT EQUAL TO (!=) Operator Example 2

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';
NOT EQUAL TO (!=) Operator Example 3

As you can see the result has all the names from other departments except "CSE" and "ME".


ADVERTISEMENT
ADVERTISEMENT




Comments and Discussions!




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.