[英]Using IN operator in SQL
假设我有一个由 T1 (a, b, c) 组成的数据库并且我还有一个数据库 T2 (a, b, c) 我可以使用 IN 运算符检查是否有从 T1 到 T2 的记录? 像这样的例子:
select a from T1 where (a, b, c) in (select a, b, c from T2)
还是 IN 运算符仅适用于单个值? 谢谢回答:)
这取决于您的数据库。 一些数据库(例如 MySQL、Postgres、Oracle)支持带有in
元组。 其他人没有(SQL Server)。
所有数据库都可以使用exists
:
select a
from T1
where exists (select 1
from t2
where t2.a = t1.a and t2.b = t1.b and t2.c = t1.c
);
您的查询可以使用exists
重写
select a
from T1 t1
where exists (select 1
from T2 t2 t1.a = t2.a and t1.b = t2.b and t1.c = t2.c)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.