谢谢你的回复 我2张表的需要检索的字段数量不同可以么? a表字段和值 id x1 x2 x3 1 x1 x2 x3 b表字段和值 aid x4 x5 1 x4 x5 这样可以么? select a.id,a.x1,a.x2,a.x3 from a where id=1 union all select b.id,b.x4,b.x5, from b where aid=1
上面写错了。这里更正下。 select a.id,a.x1,a.x2,a.x3 from a where id=1 union all select b.aid,b.x4,b.x5, from b where aid=1
(select a.id,a.x1,a.x2,a.x3 from a where id=1) union (select b.aid,b.x4,b.x5, from b where aid=1)
select a.id,a.x1,a.x2,a.x3 from a where id=1 union all select b.id,b.x4,b.x5,'' as x3 from b where aid=1第二个不加as也可以,union 后的列名是 第一个语句的列名
我2张表的需要检索的字段数量不同可以么?
a表字段和值
id x1 x2 x3
1 x1 x2 x3
b表字段和值
aid x4 x5
1 x4 x5 这样可以么?
select a.id,a.x1,a.x2,a.x3 from a where id=1
union all
select b.id,b.x4,b.x5, from b where aid=1
select a.id,a.x1,a.x2,a.x3 from a where id=1
union all
select b.aid,b.x4,b.x5, from b where aid=1
(select a.id,a.x1,a.x2,a.x3 from a where id=1)
union
(select b.aid,b.x4,b.x5, from b where aid=1)
select a.id,a.x1,a.x2,a.x3 from a where id=1
union all
select b.id,b.x4,b.x5,'' as x3 from b where aid=1第二个不加as也可以,union 后的列名是 第一个语句的列名