mysql - MySQL查询以查找表中不在列表中的ID
问题描述
我有一个大约 1000 个 id 的列表,其中只有少数 id 不在表中。我需要从列表中获取不在表中的 id。我无权创建表或将数据插入该表。
create table t1(id int);
insert into t1 values (1),(2),(3),(4),(5),(6),(7);
现在我需要获取不在表中但在 where 子句中的 id 的详细信息。
where clause - id in (2,5,8,9,25)
我的输出应该是 8,9,25
解决方案
不要把它们放在一个where
子句中。使用具有left join
或类似构造的派生表:
select i.id
from (select 2 as id union all
select 5 as id union all
select 8 as id union all
select 9 as id union all
select 25 as id
) i
where not exists (select 1 from t1 where t1.id = i.id);
推荐阅读
- python - 在 python 中更好地实现一种热编码
- spring-boot - Spring boot 2.0.9支持的Log4j2高版本是多少
- cartopy - 我如何知道哪些 NaturalEarthFeature 名称可用于 cartopy?
- spring - BeanCreationException:创建类路径资源中定义的名称为“entityManagerFactory”的bean时出错
- php - php whith json 不说话?
- spring - 带有 Avro 反序列化器的 Spring Kafka
- python - 为什么我们在 jupyter notebook 中有这么多单元而不是一个?
- ios - 在 didset 属性观察者 ios swift 中管理可编码
- spring-boot - 将 Spring JPA 实现到 COSMOS DB 的 Spring Boot 应用程序
- regex - 如何过滤 Powershell 以将目录名称与 AD SamAccountName 进行比较并忽略 .Vx 模式?