How do I SELECT none of the rows and columns in MySQL?


To display none of the rows and columns, use SELECT NULL and FALSE as in the below syntax −

select null from yourTableName where false;

Let us first create a table −

mysql> create table DemoTable1367
    -> (
    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,
    -> FirstName varchar(20)
    -> );
Query OK, 0 rows affected (0.55 sec)

Insert some records in the table using insert command −

mysql> insert into DemoTable1367(FirstName) values('Chris');
Query OK, 1 row affected (0.20 sec)
mysql> insert into DemoTable1367(FirstName) values('David');
Query OK, 1 row affected (0.10 sec)
mysql> insert into DemoTable1367(FirstName) values('Bob');
Query OK, 1 row affected (0.10 sec)

Display all records from the table using select statement −

mysql> select * from DemoTable1367;

This will produce the following output −

+----+-----------+
| Id | FirstName |
+----+-----------+
|  1 | Chris     |
|  2 | David     |
|  3 | Bob       |
+----+-----------+
3 rows in set (0.00 sec)

Following is the query to select none of the rows and columns −

mysql> select null from DemoTable1367 where false;

This will produce the following output. Empty set is visible since we have selected none of the rows and columns −

Empty set (0.00 sec)

Updated on: 08-Nov-2019

504 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements