一个select要求其中的某个字段必须在另一个select中存在怎么写sql?
比如我
集合1.select A_no from taba,tabc,tabd where *****************
集合2.select A_no from taba,tabb where *****************
集合1里可能查出重复的A_no,比如
A_no
a
a
b
b
c
d
集合2里主要是查出有效的A_no,里面A_no不重复,比如
a
c
我现在想求出的结果
A_no
a
a
c
怎么办呢。谢谢
[解决办法]
集合1
union
集合2
[解决办法]
select A_no from taba,tabc,tabd where *****************
where A_no in
(select A_no from taba,tabb where *****************)
[解决办法]
集合1.select A_no from taba,tabc,tabd where *****************UNION ALL集合2.select A_no from taba,tabb where *****************
[解决办法]
给多一个不相同的字段B2,
集合1.select A_no,B2 from taba,tabc,tabd where *****************INTERSECT集合2.select A_no,B2 from taba,tabb where *****************
[解决办法]
select A_no from taba,tabc,tabd where A_no in
(select A_no from taba,tabb where *****************)
and 其它条件
[解决办法]
select A_no from taba,tabc,tabd where *****************
and A_no in ( select A_no from taba,tabb where ***************** )
[解决办法]
select t1.a_no
from (select A_no from taba,tabc,tabd where *****************) t1
where exists
(select 1 from (select A_no from taba,tabb where *****************) t2
where t2.a_no = t1.a_no)