Can we use SELECT NULL statement in a MySQL query?



Yes, we can use the SELECT NULL statement in a MySQL query. Let us first create a table −

mysql> create table DemoTable (    Name varchar(100) ); Query OK, 0 rows affected (0.49 sec)

Insert some records in the table using insert command −

mysql> insert into DemoTable values('Chris'); Query OK, 1 row affected (0.47 sec) mysql> insert into DemoTable values('Mike'); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable values('Sam'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values('Bob'); Query OK, 1 row affected (0.27 sec) mysql> insert into DemoTable values('David'); 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 −

+-------+ | Name  | +-------+ | Chris | | Mike  | | Sam | | Bob | | David | +-------+ 5 rows in set (0.00 sec)

Following is the query to implement SELECT NULL −

mysql> select null from DemoTable where Name='Mike';

This will produce the following output −

+------+ | NULL | +------+ | NULL | +------+ 1 row in set (0.00 sec)
Updated on: 2019-09-24T12:56:07+05:30

260 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements