有两个表A(a,b,c,) B(f,e,k) 我的目的是把B表的f字段查询出来,然后接到B表a字段的后面形成一个新的字段N,N字段的记录中包括A.a 和B.f 请问这个SQL语句怎么写啊?
A表
a   b   c
1   2   3
2   3   4
B表
f   e   k
4   3   6 
8   6   5
结果
N
1

4
8

解决方案 »

  1.   

    declare @t table(a int,b int,c int)
    insert into @t select 1,2,3
    union all select 2,3,4declare @a table(f int,e int,k int)
    insert into @a select 4,3,6 
    union all select 8,6,5select a as N from @t
    union all
    select f from @a
    --这样?
      

  2.   

    select a as n from a
    union all
    select f as n from b
      

  3.   

    select a as n from a
    union all
    select f as n from b
      

  4.   

    select a as n from a
    union all
    select f as n from b