
- 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
MySQL select query to fetch data with null value?
Let us first create a table −
mysql> create table DemoTable ( CustomerName varchar(100), CustomerCountryName varchar(100) ); Query OK, 0 rows affected (0.95 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('Chris','US'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values('Bob','UK'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values('Carol',NULL); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('David','AUS'); Query OK, 1 row affected (0.32 sec) mysql> insert into DemoTable values('Mike',NULL); Query OK, 1 row affected (0.18 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+--------------+---------------------+ | CustomerName | CustomerCountryName | +--------------+---------------------+ | Chris | US | | Bob | UK | | Carol | NULL | | David | AUS | | Mike | NULL | +--------------+---------------------+ 5 rows in set (0.00 sec)
Following is the query to fetch data with null value −
mysql> select *from DemoTable where CustomerCountryName IS NULL;
This will produce the following output −
+--------------+---------------------+ | CustomerName | CustomerCountryName | +--------------+---------------------+ | Carol | NULL | | Mike | NULL | +--------------+---------------------+ 2 rows in set (0.00 sec)
- Related Articles
- MySQL query to replace null value with empty string in several columns while fetching data
- MySQL query to fetch the maximum cumulative value
- How to retrieve the corresponding value for NULL with a MySQL query?
- Fetch maximum value from multiple columns with null and non-null values?
- Can we use SELECT NULL statement in a MySQL query?
- MySQL query to fetch date with year and month?
- MySQL select query with multiple WHERE?
- MySQL query to fetch column length declared with BLOB type
- MySQL query to fetch the maximum corresponding value from duplicate column values
- How to add static value while INSERT INTO with SELECT in a MySQL query?
- MySQL query to select column where value = one or value = two, value = three, etc?
- MySQL query to select all data between range of two dates?
- MySQL query to fetch record by year
- MySQL query to fetch multiple least values?
- Select query with regular expression in MySQL

Advertisements