 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Implement two conditions for a single column in MySQL for null and empty value
Let us first create a table −
mysql> create table DemoTable635( EmployeId int NOT NULL AUTO_INCREMENT PRIMARY KEY,EmployeeName varchar(100) ); Query OK, 0 rows affected (1.24 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable635(EmployeeName) values('John'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable635(EmployeeName) values('Sam'); Query OK, 1 row affected (0.27 sec) mysql> insert into DemoTable635(EmployeeName) values(''); Query OK, 1 row affected (0.38 sec) mysql> insert into DemoTable635(EmployeeName) values(null); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable635(EmployeeName) values('David'); Query OK, 1 row affected (0.22 sec) Display all records from the table using select statement −
mysql> select *from DemoTable635;
This will produce the following output −
+-----------+--------------+ | EmployeId | EmployeeName | +-----------+--------------+ | 1 | John | | 2 | Sam | | 3 | | | 4 | NULL | | 5 | David | +-----------+--------------+ 5 rows in set (0.00 sec)
Following is the query to avoid displaying empty and null value from a MySQL column −
mysql> select *from DemoTable635 tbl where tbl.EmployeeName is not null and tbl.EmployeeName <> '';
This will produce the following output −
+-----------+--------------+ | EmployeId | EmployeeName | +-----------+--------------+ | 1 | John | | 2 | Sam | | 5 | David | +-----------+--------------+ 3 rows in set (0.02 sec)
Advertisements
 