Syntax error Ignore null values in MySQL and display rest of the values

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)
Updated on: 2019-12-10T06:32:49+05:30

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements