日期:2014-05-18  浏览次数:20486 次

可否用第一次查询的结果集为条件进行再次查询?
就是第一次select的结果不返回,而是用他为where条件直接再次select.
我说明白了么?
类似:   select   *   from   tableA   where   (select   a,b,c   from   tableB   where   d   =   "50 ")
先差出tableB表中d= "50 "的所有记录,再用这个结果集为条件来查tableA.

------解决方案--------------------
select tableA.* from (select a,b,c from tableB where d = "50 ") tableA

------解决方案--------------------
有的时候可以.如

select id , count(*) from tb group by id having count(*) = (select count(*) from t)
------解决方案--------------------
select * from tableA inner join (select a,b,c from tableB where d = "50 ") tableb
on tablea.col1=tableb.col1

select * from tableA where tablea.col1=(select a from tableB where d = "50 ")
------解决方案--------------------
select A.*,B.* from from tableA A,
(select a,b,c from tableB where d = '50 ') B
where A.a = B.a (这里为其他条件)

------解决方案--------------------
select * from (select a,b,c from tableB where d = "50 ") t where....
------解决方案--------------------
可以,其实就是子查询啊
如果楼主有什么问题,可以把语句贴出来,大家帮你分析错误
------解决方案--------------------
select a.* from tableA a inner join tableB b
on a.a=b.a and a.b=b.b and a.c=b.c
where b.d= '50 '
--这个吗?
------解决方案--------------------
select * from tableA A inner join (select * from tableB where d= '50 ') B on A.a=B.a and A.b=B.b and A.c=B.c
------解决方案--------------------
可以。其次不分開就是嵌套查詢