select *,(select Aname from A where a.no=test.no)as Objname,(select Bname from B where b.no=test.no)as Objname,(select Cname from C where c.no=test.no)as Objname  from test
请问各位大哥,有什么办法让三个Objname在同一列显示呢??上面这样查出来的数据,有三列Objname:
Objname    Objname  Objname
  1           1        5
  2           3        6要怎么才能做成:
Objname
   1
   2
   1
   3
   5
   6
谢谢各位知道的帮个忙!~

解决方案 »

  1.   

    select a.Aname as Objname,b.Bname as Objname_b,c.Cname as Objname_c
      into #tmp
      from test as x
      inner join A on x.no=a.no
      inner join B on x.no=b.no
      inner join C on x.no=c.no
    select Objname from #tmp
      union all select Objname_b from #tmp
      union all select Objname_c from #tmp
    如果不是为了保证次序一致,只要一句:
    select a.Aname as Objname
      from test as x
      inner join A on x.no=a.no
      union all
      select b.Bname
      from test as x
      inner join B on x.no=b.no
      union all
      select c.Cname
      from test as x
      inner join C on x.no=c.no
      

  2.   

    可以写三条sql语句union起来。。
      

  3.   

    select Aname as Objname from A where a.no=test.no
    union
    select Bname from B where b.no=test.no
    union
    select Cname from C where c.no=test.no