我有一个表里面有一些数据行另外一个表是没有的。我想把这个表的数据行更新插入到另外一个表上面去。
例如:name    code     values
      I        1         12
      U        1         11
上面这个表还有很多字段没加上去的。但是对另外一个表没多大用处我就想插这几个字段的数据行进去另外一个表。请问高手我要怎么做呢?

解决方案 »

  1.   

    insert into 另外一个表(name,code,values) select name,code,values from 这个表
      

  2.   

    insert into tab2(name,code,values) select name,code,values from tab1 where exists (select distinct name,code,values from tab2 where name=tab1.name,code=tab1.code,values=tab1.values)
      

  3.   

    如查列数相同,可以用以下方法
    insert a
    select * from b
    where exists(select * from a where name=b.name and code=b.code and values=b.values)
      

  4.   

    用not exists
    insert a
    select * from b
    where not exists(select * from a where name=b.name and code=b.code and values=b.values)