SQL关键字 in-待重新整理

本文详细介绍了 SQL 中 in() 子查询的使用方法,包括如何查询一个表中的数据是否包含在另一个表的集合中,以及如何指定具体值进行查询。通过多个实例展示了 in() 子查询结合不同条件的应用场景。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

in(): sql子查询 , 返回一个集合,所查集合包含在条件中。

例:select * from table_name1 as t
where t.name in(
 select t2.name from table_name2 as t2
)
and t.number = 1000
解释:查询 table_name1表 中 name包含 table_name2表 name 的数据 ,并且在table_name1表中number=1000的数据
例2:select * from table_name1 as t
where t.name in("AAA","BBB")
and t.number = 1000
解释:查询出table_name1中 t.name包含 "AAA"和"BBB" ,并且在table_name1表中number=1000的数据

例3:select * from table_name1 as t
where t.name in(
 select t2.name from table_name2 as t2
)
and t.age in(
  select t2.age from table_name2 as t2
    )
and t.number = 1000

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值