SQL如何将另一张表的某一字段里全部数值插入到本表中,同时保持不重复。
例:A表字段A   字段B
123      NULL
456      NULL
789      NULL
B表
字段A   字段B
123      NULL
456      NULL
789      NULL
012      NULL
345      NULL如何将B表里的 字段A 里的数值插入到 A表里的 字段A中,而且A表字段A已经有的值不插进去
请高手解答,在线等答案

解决方案 »

  1.   

    insert a(a) select a from b where not exists(select 1 from a where a.a=b.a)
      

  2.   


    insert into A(字段a)
    select 字段a
    from B
    where not exists (select 1 from A where 字段a = B.字段a)--where 字段a not in (select distinct 字段a from A)
      

  3.   

    insert into A(字段a)
    select 字段a
    from B
    where not exists (select 1 from A where 字段a = B.字段a)
      

  4.   

    insert a
    select from b 
    where a.字段A 
    not in (select 字段A from b)
      

  5.   

    [code=SQL]insert a
    select distinct * from b 
    where a.字段A 
    not in (select 字段A from b)[/code]
      

  6.   

    insert a
    select distinct * from b 
    where a.字段A 
    not in (select 字段A from b)
      

  7.   

    insert into table_A(A) select A from table_B b where not exists(
    select top 1 * from  table_A where A=b.A )