如题。
比如有一张表table,字段aaa和字段bbb,结构如下:
aaa                bbb
13411111111        13522222222
13433333333        13544444444
13455555555        13566666666
13477777777        13588888888现在想把字段b的所有记录追加插入到字段a中,得到结果为:
aaa
13411111111        
13433333333        
13455555555        
13477777777        
13522222222
13544444444
13566666666
13588888888请问sql语句怎么写?

解决方案 »

  1.   

    insert into table(aaa)
    select bbb from table;delete from table
    where aaa is not null and bbb is null;
      

  2.   

    为什么还要下面那句delete 语句呢 aaa is not null 不是把aaa原来的记录都删除了么
      

  3.   

    insert into tb(aaa) select bbb from tb
      

  4.   


    drop table #temp
    create table #temp
    (
    aaa varchar(100),
    bbb varchar(100))
    goinsert into #temp values('13411111111', '13522222222')
    insert into #temp values('13433333333', '13544444444')
    insert into #temp values('13455555555', '13566666666')
    insert into #temp values('13477777777', '13588888888')
    goselect * from #tempselect a.aaa as aaa from #temp a
    union 
    select b.bbb from #temp b
      

  5.   

    insert into tb
    select bbb,''
    from tb
    where bbb not in (select aaa from tb)
      

  6.   

    insert into table(aaa)
    select bbb from table 
      

  7.   


    --插入结果到一个临时表
    select *
    into #temp
    from (
    select aaa from your_table
    union all
    select bbb from your_table
    ) a
      

  8.   

    insert into tablename(aaa)
    values select bbb from tablename