我有两个查询,我想检查查询A返回的PopulateKode
中是否存在查询A中的PopulateKode
之一。
我该怎么做?
这是我的疑问:
QUERY A:
select KodePosition as PopulateKode from Position where UserLogin='winz\siti.azzahra'
A的结果集:
PopulateKode
0041
0139
QUERY B:
SELECT (A.IdPositiionPengirim +';'+ B.KodeJabatan)as PopulateKode
FROM SuratKeluar as A
join SuratKeluarD as B on A.Id=B.IdSuratKeluar
where A.Id='60083a60-2643-45b5-8b59-c6094ec8b79d'
B的结果集
PopulateKode
0037
0038
答案 0 :(得分:0)
我会将IN()
与UNION
一起使用,因此查询B中的每个值都是独立的:
select KodePosition as PopulateKode
from Position
where UserLogin='winz\siti.azzahra'
and KodePosition IN (
SELECT A.IdPositiionPengirim
FROM SuratKeluar as A
join SuratKeluarD as B on A.Id=B.IdSuratKeluar
where A.Id='60083a60-2643-45b5-8b59-c6094ec8b79d'
UNION
SELECT B.KodeJabatan
FROM SuratKeluar as A
join SuratKeluarD as B on A.Id=B.IdSuratKeluar
where A.Id='60083a60-2643-45b5-8b59-c6094ec8b79d')