select * from ( select * from .....) as a, ( select * from .....) as bwhere a.id=*b.id
把* 改为a.* select a.* from ( select * from .....) as a, ( select * from .....) as bwhere .....
select * from test a left join test11 b on a.id=b.id
意思是这样: select a.*, b.field_1 from ( select * from .....) as a, ( select b.field_1 from .....) as bwhere a.id=b.id a有数据,而b为空, 为何输出就空了,如何才能在b无数据的时候让a的数据输出,不知这样大家有没有明白?
select a.*, b.field_1 from ( select * from .....) as a, ( select b.field_1 from .....) as bwhere a.id=b.id --因为没有符合条件的记录,所以无结果
--改为这个就行了. select a.*, b.field_1 from (select * from .....) as a left join (select b.field_1 from .....) as b on a.id=b.id
如果子查询中没有where条件,就不要写成子查询,直接用原表:select a.*, b.field_1 from table1 a left join table2 b on a.id=b.id
如果a表和b表结构相同, select u.* from (( select * from .....) as a union all ( select * from .....) as b ) as u
( select * from .....) as a,
( select * from .....) as bwhere a.id=*b.id
select a.* from
( select * from .....) as a,
( select * from .....) as bwhere .....
left join test11 b on a.id=b.id
select a.*, b.field_1 from
( select * from .....) as a,
( select b.field_1 from .....) as bwhere a.id=b.id
a有数据,而b为空,
为何输出就空了,如何才能在b无数据的时候让a的数据输出,不知这样大家有没有明白?
( select * from .....) as a,
( select b.field_1 from .....) as bwhere a.id=b.id --因为没有符合条件的记录,所以无结果
select a.*, b.field_1 from
(select * from .....) as a left join
(select b.field_1 from .....) as b
on a.id=b.id
from table1 a left join table2 b on a.id=b.id
select u.* from
(( select * from .....) as a
union all
( select * from .....) as b
) as u