三个表(三个表:table1,table2,table3)
现在,我把这table2,table3中的记录拷贝到table1中。
条件为:dw,fhdate不同的记录。请问我用sql语句我应怎么做???

解决方案 »

  1.   

    into table1 select * from table2,table3 where table2.dw <> table3.dw and table3.fhdate <> table3.fhdate
      

  2.   

    我要的是:
    table1.dw<>table2.dw and table1.dw<>table3.dw  etc..怎么做???table1在条件也是存在的。
      

  3.   

    insert into table1 
    select * from table2 where table2.dw not in (select dw from table1)
    insert into table1 
    select * from table3 where table3.dw not in (select dw from table1)
      

  4.   

    把问题说详细点
    如果是TABLE1、TABLE2、TABLE3的结构都相同,只是要把DW和FHDATE都不相同的记录都COPY进去而已那就这样写分两次:
    insert into table1 
    select * from table2 where (table2.dw not in (select dw from table1)
    insert into table1)and (table2.fhdate not in (select fhdate from table1)) 
    select * from table3 where (table3.dw not in (select dw from table1)
    )and(select table3.fhdate not in (select fhdate from table3))