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

Advertisements