如何在 MySQL 中将 ID 列选择为 null?
我们首先创建一个表。创建表的查询如下
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)
以下是在选择仅为 NULL 的 ID 列的查询
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)
广告
数据结构
网络
关系数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程语言
C++
C#
MongoDB
MySQL
JavaScript
PHP