
- 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
Perform MySQL SELECT on fields containing null values?
To check for NULL values in SELECT, use MySQL NULL. Let us first create a table −
mysql> create table DemoTable1455 -> ( -> Name varchar(20) -> ); Query OK, 0 rows affected (0.47 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1455 values('John'); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable1455 values(NULL); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable1455 values(''); Query OK, 1 row affected (0.19 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable1455;
This will produce the following output −
+------+ | Name | +------+ | John | | NULL | | | +------+ 3 rows in set (0.00 sec)
Following is the query to perform MySQL select on fields containing null values −
mysql> select * from DemoTable1455 where Name <> 'John' or Name is null;
This will produce the following output −
+------+ | Name | +------+ | NULL | | | +------+ 2 rows in set (0.00 sec)
- Related Articles
- Perform MySQL SELECT on dates inserted into the table as VARCHAR values
- Perform mathematical calculations in a MySQL table with NULL and NON-NULL values
- Select different fields in MySQL even if a field is set to null?
- Update all the fields in a table with null or non-null values with MySQL
- MySQL query to order by two fields and NULL values in chronological order?
- Perform multiplication in SELECT depending on column value in MySQL?
- SELECT WHERE IN null in MySQL?
- Match MongoDB documents with fields not containing values in array?
- Perform case insensitive SELECT using MySQL IN()?
- Perform MySQL SELECT INTO user-defined variable
- MySQL Select Multiple VALUES?
- Count only null values in two different columns and display in one MySQL select statement?
- Select column names containing a string in MySQL?
- How to use NULL in MySQL SELECT statement?
- How to perform SELECT using COUNT in MySQL?

Advertisements