为此,您可以使用NOTIN()方法。
让我们首先创建一个表-mysql> create table DemoTable718 (
Id int,
FirstName varchar(100),
Age int
);
使用插入命令在表中插入一些记录-mysql> insert into DemoTable718 values(101,'Chris',26);
mysql> insert into DemoTable718 values(102,'Robert',24);
mysql> insert into DemoTable718 values(103,'David',27);
mysql> insert into DemoTable718 values(104,'Mike',28);
mysql> insert into DemoTable718 values(105,'Sam',23);
使用select语句显示表中的所有记录-mysql> select *from DemoTable718;
这将产生以下输出-+------+-----------+------+
| Id | FirstName | Age |
+------+-----------+------+
| 101 | Chris | 26 |
| 102 | Robert | 24 |
| 103 | David | 27 |
| 104 | Mike | 28 |
| 105 | Sam | 23 |
+------+-----------+------+
5 rows in set (0.00 sec)
这是查询以查找不在set数组中的所有记录-mysql> select *from DemoTable718 where Id NOT IN('101','103','104');
这将产生以下输出-+------+-----------+------+
| Id | FirstName | Age |
+------+-----------+------+
| 102 | Robert | 24 |
| 105 | Sam | 23 |
+------+-----------+------+
2 rows in set (0.00 sec)