如何在 MySQL 中选择不包含任何行和列?


要显示不含任何行和列,请使用 SELECT NULL 和 FALSE,如以下语法所示 -

select null from yourTableName where false;

让我们首先创建一个表 -

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

使用 insert 命令在表中插入一些记录 -

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)

使用 select 语句显示表中的所有记录 -

mysql> select * from DemoTable1367;

这将产生以下输出 -

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

以下是如何查询不选择任何行和列 -

mysql> select null from DemoTable1367 where false;

这将产生以下输出。空集可见,因为我们没有选择任何行和列 -

Empty set (0.00 sec)

更新于: 2019-11-08

625 次查看

启动您的 职业

通过完成课程获得认证

立即开始
广告
© . All rights reserved.