select a.id,a.xx1,a.xx2 from a where id=1
union all
select b.id,b.xx1,b.xx2 from b where id=1

解决方案 »

  1.   

    谢谢你的回复
    我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
      

  2.   

    上面写错了。这里更正下。
    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
      

  3.   


    (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)
      

  4.   


    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 后的列名是 第一个语句的列名