
- 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
Difference Between MySql <> NULL and IS NOT NULL?
If you compare the <> operator with NULL value then you will get NULL value always and no result.
Let us see some examples for comparison −
mysql> select 10 <> NULL; +------------+ | 10 <> NULL | +------------+ | NULL | +------------+ 1 row in set (0.00 sec) mysql> select NULL <> NULL; +--------------+ | NULL <> NULL | +--------------+ | NULL | +--------------+ 1 row in set (0.00 sec) mysql> select 'Chris' <> NULL; +-----------------+ | 'Chris' <> NULL | +-----------------+ | NULL | +-----------------+ 1 row in set (0.00 sec) mysql> select '' <> NULL; +------------+ | '' <> NULL | +------------+ | NULL | +------------+ 1 row in set (0.00 sec)
Let us first create a table −
mysql> create table DemoTable846(Value int); Query OK, 0 rows affected (0.93 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable846 values(NULL); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable846 values(10); Query OK, 1 row affected (0.11 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable846;
This will produce the following output −
+-------+ | Value | +-------+ | NULL | | 10 | +-------+ 2 rows in set (0.00 sec)
Following is the result for IS NOT NULL operator −
mysql> select *from DemoTable846 where Value IS NOT NULL;
This will produce the following output −
+-------+ | Value | +-------+ | 10 | +-------+ 1 row in set (0.00 sec)
Here is the result for <> operator. Following is the query −
mysql> select *from DemoTable846 where Value <> NULL; Empty set (0.00 sec)
- Related Articles
- In MySQL what is the difference between != NULL and IS NOT NULL?
- Working with NULL and IS NOT NULL in MySQL
- What is the benefit of MySQL ‘IS NULL’ and ‘IS NOT NULL’?
- Display only NOT NULL values from a column with NULL and NOT NULL records in MySQL
- What is the difference between MySQL ISNULL() function and IS NULL operator?
- Insert default into not null column if value is null in MySQL?
- Conditional NOT NULL case MySQL?
- Display NULL and NOT NULL records except a single specific value in MySQL
- What is MySQL NOT NULL constraint and how can we declare a field NOT NULL while creating a table?
- Sum if all rows are not null else return null in MySQL?
- Check for NULL or NOT NULL values in a column in MySQL
- Display the result with not null value first and then with null value in MySQL
- What is the difference between null and undefined in JavaScript?
- Return null for date_format when input is null in MySQL?
- Removing NOT NULL restriction from column in MySQL?

Advertisements