查询结果:
-------
名称A
名称B
select t_num from table_b where id=81
查询结果:
-------
3
2
------我需要以下的结果
名称A 3
名称B 2
7 个解决方案
#1
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
#2
select a.name ,b.t_num
from table_A a ,table_b b
where a.id = b.t_id
and b.id=81
#3
select a.name ,b.t_num
from table_A a ,table_b b
where a.id = b.t_id
and b.id=81
from table_A a ,table_b b
where a.id = b.t_id
and b.id=81
#4
select a.name , b.t_num
from table_a a , table_b b
where a.id = b.t_id and b.id = 81
from table_a a , table_b b
where a.id = b.t_id and b.id = 81
#5
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
#6
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
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
#7
select A.name, B.t_num
from table_A A
left join table_b B
on A.id = B.id
where B.id=81
楼主好好体会SQL其中的乐趣。
#1
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
#2
select a.name ,b.t_num
from table_A a ,table_b b
where a.id = b.t_id
and b.id=81
#3
select a.name ,b.t_num
from table_A a ,table_b b
where a.id = b.t_id
and b.id=81
from table_A a ,table_b b
where a.id = b.t_id
and b.id=81
#4
select a.name , b.t_num
from table_a a , table_b b
where a.id = b.t_id and b.id = 81
from table_a a , table_b b
where a.id = b.t_id and b.id = 81
#5
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
#6
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
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
#7
select A.name, B.t_num
from table_A A
left join table_b B
on A.id = B.id
where B.id=81
楼主好好体会SQL其中的乐趣。