如何在 MySQL 中选择 ID 列为空?
mysqlmysqli database更新于 2025/3/23 22:36:17
首先我们创建一个表。创建表的查询如下
mysql> create table selectAllDemo - > ( - > Name varchar(100), - > Age int - > ); Query OK, 0 rows affected (1.90 sec)
使用 insert 命令在表中插入一些记录。
查询如下
mysql> insert into selectAllDemo values('John',25);
Query OK, 1 row affected (0.99 sec)
mysql> insert into selectAllDemo values('Carol',26);
Query OK, 1 row affected (0.42 sec)
mysql> insert into selectAllDemo values('Bob',30);
Query OK, 1 row affected (1.57 sec)
mysql> insert into selectAllDemo values('Sam',35);
Query OK, 1 row affected (0.26 sec)
使用 select 语句显示表中的所有记录。
查询如下
mysql> select *from selectAllDemo;
以下是输出 −
+-------+------+ | Name | Age | +-------+------+ | John | 25 | | Carol | 26 | | Bob | 30 | | Sam | 35 | +-------+------+ 4 rows in set (0.16 sec)
以下查询仅选择 ID 列为 NULL
mysql> select NULL AS Id,tbl.Name,tbl.Age from selectAllDemo tbl where Age=35;
以下是输出 −
+------+------+------+ | Id | Name | Age | +------+------+------+ | NULL | Sam | 35 | +------+------+------+ 1 row in set (0.07 sec)
相关文章
有用资源
mysql 参考教程 - 该教程包含有关 mysql 的更多信息:https://www.cainiaomax.com/mysql/

