MySQL Not Equal

MySQL Not Equal is an inequality operator that used for returning a set of rows after comparing two expressions that are not equal. The MySQL contains two types of Not Equal operator, which are (< >) and (! =).

Difference Between (< >) and (! =) Operator

The Not Equal operators in MySQL works the same to perform an inequality test between two expressions. They always give the same result. However, they contain one difference that “< >” follows the ISO standard whereas “!=” does not follow ISO standard.

Example 1

Let us create a table student to understand how Not Equal operator works in MySQL. Suppose the “students” table contains the following data:

Table: students

MySQL Not Equal

If you want to get the student details who do not belong to England, then you need to execute the following statement:

snippet
SELECT * FROM students WHERE city <> "England";

OR,

snippet
SELECT * FROM students WHERE city != "England";

After successful execution of the above queries, we will get the same output as below:

MySQL Not Equal

Example 2

In this example, we are going to understand how Not Equal operator works with Group By clause. We can use the Group By clause for grouping rows that have the same data. If we want to get all customers who do not have cellphone number and duplicate income value, execute the following statement:

snippet
SELECT * FROM customers
JOIN contacts ON customer_id = contact_id 
WHERE cellphone <> "Null"
GROUP BY income;

We will get the following output:

MySQL Not Equal

Example 3

In this example, we are going to understand how Not Equal operator works with a JOIN statement. Let us create a table "contacts" and "customers" in a database that contains the following data:

Table: contacts

MySQL Not Equal

Table: customers

MySQL Not Equal

If we want to get all the records from table customers and contacts where the cellphone is Null, execute the following statement that returns all customers who do not have a cellphone number:

snippet
SELECT * FROM customers
JOIN contacts ON customer_id = contact_id 
WHERE cellphone != "Null;

After successful execution, it will give the following output:

MySQL Not Equal

Example 4

In this example, we are going to understand how the Not Equal operator works with multiple conditions in the WHERE clause. For example, we want to get the customer details where income is higher than 40000, and occupation is not a developer. Execute the following statement to get the result:

snippet
SELECT * FROM customers Where income>40000 and occupation<>"Developer";

After the successful execution of the above statement, we will get the following output.

MySQL Not Equal
Related Tutorial
Follow Us
https://www.facebook.com/Rookie-Nerd-638990322793530 https://twitter.com/RookieNerdTutor https://plus.google.com/b/117136517396468545840 #
Contents +