
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
Does NOT EQUAL exist in MySQL?
Yes, NOT EQUAL exist in MySQL in the fome of <> operator. The syntax is as follows−
SELECT * FROM yourTableName WHERE yourColumnName <> yourValue;
To understand the above syntax, let us create a table. The query to create a table is as follows−
mysql> create table DoesNotEqualDemo -> ( -> Id int NOT NULL AUTO_INCREMENT, -> Name varchar(20), -> PRIMARY KEY(Id) -> ); Query OK, 0 rows affected (0.98 sec)
Insert some records in the table using insert command. The query to insert record is as follows−
mysql> insert into DoesNotEqualDemo(Name) values(NULL); Query OK, 1 row affected (0.24 sec) mysql> insert into DoesNotEqualDemo(Name) values('John'); Query OK, 1 row affected (0.18 sec) mysql> insert into DoesNotEqualDemo(Name) values('Carol'); Query OK, 1 row affected (0.43 sec) mysql> insert into DoesNotEqualDemo(Name) values('Bob'); Query OK, 1 row affected (0.13 sec) mysql> insert into DoesNotEqualDemo(Name) values(''); Query OK, 1 row affected (0.13 sec) mysql> insert into DoesNotEqualDemo(Name) values('Larry'); Query OK, 1 row affected (0.13 sec) mysql> insert into DoesNotEqualDemo(Name) values(NULL); Query OK, 1 row affected (0.10 sec)
Display all records from the table using select statement. The query is as follows−
mysql> select *from DoesNotEqualDemo;
The following is the output−
+----+-------+ | Id | Name | +----+-------+ | 1 | NULL | | 2 | John | | 3 | Carol | | 4 | Bob | | 5 | | | 6 | Larry | | 7 | NULL | +----+-------+ 7 rows in set (0.00 sec)
Here is the query to select all records which are not equal to NULL as well as empty string−
mysql> select *from DoesNotEqualDemo where Name <> 'NULL' and Name <> '';
The following is the output−
+----+-------+ | Id | Name | +----+-------+ | 2 | John | | 3 | Carol | | 4 | Bob | | 6 | Larry | +----+-------+ 4 rows in set (0.00 sec)
- Related Articles
- MySQL create user if it does not exist?
- Create view in MySQL only if it does not already exist?
- Select from table where value does not exist with MySQL?
- Do Double Equal Sign exist in MySQL?
- Java Selenium Chromedriver.exe Does not Exist IllegalStateException
- How to insert only those records that does not exist in a MySQL table?
- MySQL SELECT from table A that does not exist in table B using JOINS?
- How to select from MySQL table A that does not exist in table B?
- Insert records in MongoDB collection if it does not exist?
- Using “not equal” in MySQL?
- How to check if a table exists in MySQL and create if it does not already exist?
- What is the use of EXIST and EXIST NOT operator with MySQL subqueries?
- PHP and MYSQL database connection and table creation only once if it does not already exist?
- How does MySQL evaluate the expression if the arguments are not equal in NULLIF()?
- Add object to array in JavaScript if name does not already exist?

Advertisements