- 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
MySQL query to display records on the basis of conditions IS NULL OR !=1;?
Let us first create a table −
mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, Name varchar(100), Score int ); Query OK, 0 rows affected (1.10 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable(Name,Score) values('John',45); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable(Name,Score) values('Chris',null); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable(Name,Score) values('David',null); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable(Name,Score) values('Bob',1); Query OK, 1 row affected (0.11 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+----+-------+-------+ | Id | Name | Score | +----+-------+-------+ | 1 | John | 45 | | 2 | Chris | NULL | | 3 | David | NULL | | 4 | Bob | 1 | +----+-------+-------+ 4 rows in set (0.00 sec)
Following is the query to display records on the basis of conditions IS NULL OR !=1 −
mysql> select *from DemoTable where Score IS NULL OR Score!=1;
This will produce the following output −
+----+-------+-------+ | Id | Name | Score | +----+-------+-------+ | 1 | John | 45 | | 2 | Chris | NULL | | 3 | David | NULL | +----+-------+-------+ 3 rows in set (0.00 sec)
Advertisements