
- 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
How to skip blank and null values in MySQL?
To skip blank and null in MySQL, use the following syntax:
select *from yourTableName where yourColumnName IS NOT NULL AND yourColumnName <> '';
Let us first create a table:
mysql> create table DemoTable (Id int, FirstName varchar(20)); Query OK, 0 rows affected (0.66 sec)
Following is the query to insert records in the table using insert command:
mysql> insert into DemoTable values(100,'Larry'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values(101,''); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values(102,'Chris'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values(103,null); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values(104,' '); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values(105,'Robert'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values(106,null); Query OK, 1 row affected (0.13 sec)
Following is the query to display records from the table using select command:
mysql> select *from DemoTable;
This will produce the following output with blank values and NULL:
+------+-----------+ | Id | FirstName | +------+-----------+ | 100 | Larry | | 101 | | | 102 | Chris | | 103 | NULL | | 104 | | | 105 | Robert | | 106 | NULL | +------+-----------+ 7 rows in set (0.00 sec)
Following is the query to skip blank values as well as null in MySQL:
mysql> select *from DemoTable where FirstName IS NOT NULL AND FirstName <> '';
This will produce the following output
+------+-----------+ | Id | FirstName | +------+-----------+ | 100 | Larry | | 102 | Chris | | 105 | Robert | +------+-----------+ 3 rows in set (0.03 sec)
- Related Articles
- MySQL update column to NULL for blank values
- How to Copy and Paste Skip Blank Cells in Excel?
- How to count null values in MySQL?
- Updating blank cells to NULL will cause all cells to be NULL in MySQL?
- How to concat Values in MySQL Query and to handle Null values as well?
- How to skip rows in MySQL?
- How to split MongoDB query and skip 5 values?
- MySQL always returning the bit values as blank? How to get the original values?
- Ignore null values in MySQL and display rest of the values
- How MySQL handles the empty and null values for enumerations?
- How to check for null, undefined, or blank variables in JavaScript?
- Display and concatenate records ignoring NULL values in MySQL
- Perform mathematical calculations in a MySQL table with NULL and NON-NULL values
- MySQL query to order by NULL values
- Display only NOT NULL values from a column with NULL and NOT NULL records in MySQL

Advertisements