在MySQL中选择WHERE IN null吗?
以下是语法-
selectyourColumnName1,
yourColumnName2,
yourColumnName3,
.
.
.
N
from yourTableName
where yourValue in(yourColumnName1,yourColumnName2) or yourColumnName1 is NULL;
让我们创建一个表-
mysql> create table demo60−> (
−> id int not null auto_increment primary key,
−> first_name varchar(20),
−> last_name varchar(20)
−> )
−> ;
借助insert命令将一些记录插入表中-
mysql> insert into demo60(first_name,last_name) values('John','Smith');mysql> insert into demo60(first_name,last_name) values('John','Doe');
mysql> insert into demo60(first_name,last_name) values(null,'Brown');
mysql> insert into demo60(first_name,last_name) values('David','Miller');
mysql> insert into demo60(first_name,last_name) values('David','Smith');
mysql> insert into demo60(first_name,last_name) values('Chris','Brown');
使用select语句显示表中的记录-
mysql> select *from demo60;
这将产生以下输出-
+----+------------+-----------+| id | first_name | last_name |
+----+------------+-----------+
| 1 | John | Smith |
| 2 | John | Doe |
| 3 | NULL | Brown |
| 4 | David | Miller |
| 5 | David | Smith |
| 6 | Chris | Brown |
+----+------------+-----------+
6 rows in set (0.00 sec)
以下是选择NULL的查询-
Mysql> select−> id,
−> first_name,
−> last_name
−> from demo60
−> where 'John' in(first_name,last_name) or first_name is NULL;
这将产生以下输出-
+----+------------+-----------+| id | first_name | last_name |
+----+------------+-----------+
| 1 | John | Smith |
| 2 | John | Doe |
| 3 | NULL | Brown |
+----+------------+-----------+
3 rows in set (0.00 sec)
以上是 在MySQL中选择WHERE IN null吗? 的全部内容, 来源链接: utcz.com/z/359453.html