在sql中  我有两个表 一个4000多数据 一个6000多条数据 这两个表内容一样 那个4000多是从6000多条数据里拿出来的 ,
现在我想联合查询 这两个表不同的数据 然后提出来 放在另一个表中 。各位怎么写啊?

解决方案 »

  1.   

    insert newtable
    select a.*
    from tab6000 a left join tab4000
    on a.key = b.key
    where b.key is null
      

  2.   

    select * from table_a where id not in (select id from table_b)
      

  3.   

    or :insert newtable
    select a.*
    from tab6000 a 
    where not exists (
    select 1
    from tab4000 b
    on a.key = b.key
    )
      

  4.   

    修正3楼insert newtable
    select a.*
    from tab6000 a 
    where not exists (
    select 1
    from tab4000 b
    where a.key = b.key
    )
      

  5.   

    select A.* from A where A.ID not in (select B.ID From B)
    A:6000多条数据表
    B:4000多条数据表
    ID:为主键
    这样就可以提取出所有的不同数据插入到另一个表中了
      

  6.   


    --A表是6000多条数据表
    --B表是4000多条数据表
    --C表是新生成的表
    insert into C
    select * from A t1 where not exists(select 1 from B where id=t1.id)
      

  7.   

    insert into newtable
    select*from A
    except
    select*from B注:1、事先建好newtable表结构
        2、A为大表,B为小表。
      

  8.   

    假如4000条数据的表是AA 6000的是BB
    那么 SELECT B.* FROM AA A,BB B WHERE B.关键字段 not in (select 关键字段 from AA)
      

  9.   

    insert into C
    select * from A t1 where not exists(select 1 from B where id=t1.id)
      

  10.   

    insert newtable
    select a.*
    from tab6000 a 
    where not exists (
    select 1
    from tab4000 b
    on a.key = b.key
    )