
- 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
Ignore null values in MySQL and display rest of the values
Use IS NOT NULL to find the non-null values and display them. Let us first create a table −
mysql> create table DemoTable1458 -> ( -> StudentName varchar(20), -> StudentScore int -> ); Query OK, 0 rows affected (0.52 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1458 values('Chris Brown',56); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable1458 values('David Miller',NULL); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable1458 values('John Doe',78); Query OK, 1 row affected (0.08 sec) mysql> insert into DemoTable1458 values('Adam Smith',NULL); Query OK, 1 row affected (0.12 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable1458;
This will produce the following output −
+--------------+--------------+ | StudentName | StudentScore | +--------------+--------------+ | Chris Brown | 56 | | David Miller | NULL | | John Doe | 78 | | Adam Smith | NULL | +--------------+--------------+ 4 rows in set (0.00 sec)
Here is the query to ignore null values −
mysql> select StudentName,StudentScore from DemoTable1458 -> where StudentScore IS NOT NULL;
This will produce the following output −
+-------------+--------------+ | StudentName | StudentScore | +-------------+--------------+ | Chris Brown | 56 | | John Doe | 78 | +-------------+--------------+ 2 rows in set (0.00 sec)
- Related Articles
- Ignore NULL values from separate tables in a single MySQL query and display count of NOT NULL records
- Ignore null values in MongoDB documents
- Display 1 for NULL values in MySQL
- Display and concatenate records ignoring NULL values in MySQL
- Ignore MySQL INSERT IGNORE statement and display an error if duplicate values are inserted in a table
- Display first non-null values with coalesce() in MySQL?
- MySQL query to display only the empty and NULL values together?
- Display only NOT NULL values from a column with NULL and NOT NULL records in MySQL
- Ignore NULL and UNDEFINED values while running a MongoDB query
- MySQL query to compare and display only the rows with NULL values
- Ignore first 4 values in MongoDB documents and display the next 3?
- Fix a specific column value and display random values for rest of the rows in MySQL
- Display custom text in a new column on the basis of null values in MySQL?
- Count only null values in two different columns and display in one MySQL select statement?
- Query non-empty values of a row first in ascending order and then display NULL values

Advertisements