首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > oracle >

一个select要求其中的某个字段必须在另一个select中存在如何写sql

2012-03-19 
一个select要求其中的某个字段必须在另一个select中存在怎么写sql?比如我集合1.select A_no from taba,tab

一个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 *****************)

[解决办法]

探讨

select A_no from taba,tabc,tabd where *****************
where A_no in
(select A_no from taba,tabb where *****************)

[解决办法]
SQL code
集合1.select A_no from taba,tabc,tabd where *****************UNION ALL集合2.select A_no from taba,tabb where *****************
[解决办法]

给多一个不相同的字段B2,
SQL code
集合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)

热点排行
Bad Request.