从表中选择MySQL不存在值的表?
对于这一点,你可以使用NOT IN()
-
mysql> create table DemoTable1991(
StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,
StudentName varchar(20)
);
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable1991(StudentName) values('Chris');mysql> insert into DemoTable1991(StudentName) values('Bob');
mysql> insert into DemoTable1991(StudentName) values('David');
mysql> insert into DemoTable1991(StudentName) values('Sam');
mysql> insert into DemoTable1991(StudentName) values('Mike');
使用select语句显示表中的所有记录-
mysql> select * from DemoTable1991;
这将产生以下输出-
+-----------+-------------+| StudentId | StudentName |
+-----------+-------------+
| 1 | Chris |
| 2 | Bob |
| 3 | David |
| 4 | Sam |
| 5 | Mike |
+-----------+-------------+
5 rows in set (0.03 sec)
这是从不存在值的表中选择*的查询:
mysql> select * from DemoTable1991where StudentName NOT IN('Bob','Sam','Mike');
这将产生以下输出-
+-----------+-------------+| StudentId | StudentName |
+-----------+-------------+
| 1 | Chris |
| 3 | David |
+-----------+-------------+
2 rows in set (0.04 sec)
以上是 从表中选择MySQL不存在值的表? 的全部内容, 来源链接: utcz.com/z/335084.html