日期:2014-05-16  浏览次数:20978 次

怎么把两个查询结果连接起来
select name from table_A where id in (select t_id from table_b where id=81)

查询结果:
-------
名称A
名称B

select t_num from table_b where id=81

查询结果:
-------
3
2

------我需要以下的结果
名称A 3
名称B 2

------解决方案--------------------
SQL code
select a.name,b.t_num from table_A a,(select t_id,t_num from table_b where id=81)
)b where a.id=b.t_id

------解决方案--------------------
SQL code

select a.name ,b.t_num  
from table_A a ,table_b b
where a.id = b.t_id 
and b.id=81

------解决方案--------------------
select a.name ,b.t_num
from table_A a ,table_b b
where a.id = b.t_id 
and b.id=81

------解决方案--------------------
select a.name , b.t_num
from table_a a , table_b b
where a.id = b.t_id and b.id = 81
------解决方案--------------------
SQL code
SELECT 
    a.NAME,b.t_num
FROM table_A AS a
    INNER JOIN table_b AS b ON a.ID=b.t_id
WHERE b.ID=81

------解决方案--------------------
select tt.name,
ss.t_num
from
(select name from table_A t where id in (select t_id from table_b where id=81)) tt,
(select t_num from table_b s where id=81) ss
------解决方案--------------------
SQL code

select A.name, B.t_num  
  from table_A A
  left join table_b B 
  on A.id = B.id
  where  B.id=81