table1 

f1 ,f2 , f3
1    2    3
4    5    6表table2

f4,  f5,f6
7    8   9
10  12   11现在想实现的结果是
列  
fdjbh(内容包括table1中的f1跟table2中的f4)   fnr(包含f3,f6这两列的内容)1                                          3
4                                          6
7                                          9
10                                         11
两个表没有任何关联
 

解决方案 »

  1.   

    select f1,f3 from fdjbh 
    union all
    select f4,f6 from fnr
      

  2.   

    select f1,f3 from table1 union select f4,f6 from table2
      

  3.   

    select f1,f3 from table1
    union all
    select f4,f6 from table2
      

  4.   

    select f1,f3 from table1
    union all
    select f4,f6 from table2
      

  5.   

    select f1 , f3 from table1
    union all
    select f4 , f6 from table2
      

  6.   

    ---测试数据---
    if object_id('[table1]') is not null drop table [table1]
    go
    create table [table1]([f1] int,[f2] int,[f3] int)
    insert [table1]
    select 1,2,3 union all
    select 4,5,6
    if object_id('[table2]') is not null drop table [table2]
    go
    create table [table2]([f4] int,[f5] int,[f6] int)
    insert [table2]
    select 7,8,9 union all
    select 10,12,11
     
    ---查询---
    select f1,f3 from table1
    union all
    select f4,f6 from table2---结果---
    f1          f3          
    ----------- ----------- 
    1           3
    4           6
    7           9
    10          11(所影响的行数为 4 行)
      

  7.   

    create table table1 (f1 int,f2 int, f3 int) 
    insert into table1 values(1 , 2 , 3 )
    insert into table1 values(4 , 5 , 6 )
    create table table2 (f4 int, f5 int,f6 int) 
    insert into table2 values(7 , 8 , 9 )
    insert into table2 values(10, 12 , 11) 
    goselect f1 fdjbh, f3 fnr from table1 
    union all 
    select f4 , f6 from table2drop table table1 , table2/*
    fdjbh       fnr         
    ----------- ----------- 
    1           3
    4           6
    7           9
    10          11(所影响的行数为 4 行)
    */
      

  8.   

    --哦,写错了,重写select f1 as fdjbh,f3 as fnr from table1
    union all 
    select f4,f6 from table2
      

  9.   

    select fdjbh = f1,  fnr = f3
    from #table1
    union
    select f4,f6
    from #table2
    这个应该可以满足你的要求
      

  10.   

    select f1,f3 from table1
    union all
    select f4,f6 from table2
      

  11.   

    select f1,f3 from fdjbh 
    union all 
    select f4,f6 from fnr