- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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)
- Related Articles
- Fetching records from a table with NULL and other values on the basis of conditions in MySQL
- Use NOT IN, OR and IS NULL in the same MySQL query to display filtered records
- MySQL query to ORDER BY records on the basis of modulus result
- Display records on the basis of key-value pairs in MySQL
- MySQL TINYINT type to return 1 or IS NULL records
- How to display the day name on the basis of Date of Birth records in MySQL?
- MongoDB query to count records on the basis of matching criteria
- Display records ignoring NULL in MySQL
- MySQL query to select records from a table on the basis of a particular month number?
- Display custom text in a new column on the basis of null values in MySQL?
- Ignore NULL values from separate tables in a single MySQL query and display count of NOT NULL records
- Add a column count in a MySQL query on the basis of last name records?
- Search records on the basis of date in MySQL?
- MySQL db query to fetch records from comma separate values on the basis of a specific value
- MySQL query to remove Null Records in a column?

Advertisements