- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Display NULL and NOT NULL records except a single specific value in MySQL
To display NULL records, use IS NULL in MySQL. To ignore a single value, use the != operator , which is an alias of the <> operator.
Let us first create a table −
mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, PlayerName varchar(40) ); Query OK, 0 rows affected (0.50 sec)
Insert some records in the table using insert command −p>
mysql> insert into DemoTable(PlayerName) values('Adam'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable(PlayerName) values(NULL); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable(PlayerName) values('Sam'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable(PlayerName) values('Mike'); Query OK, 1 row affected (0.08 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+----+------------+ | Id | PlayerName | +----+------------+ | 1 | Adam | | 2 | NULL | | 3 | Sam | | 4 | Mike | +----+------------+ 4 rows in set (0.00 sec)
Following is the query to display NULL and NOT NULL records, ignoring a single specific record −
mysql> select *from DemoTable where PlayerName!='Sam' or PlayerName IS NULL;
This will produce the following output −
+----+------------+ | Id | PlayerName | +----+------------+ | 1 | Adam | | 2 | NULL | | 4 | Mike | +----+------------+ 3 rows in set (0.00 sec)
Advertisements