例如:當我用select語句查詢出值 :
字段1......字段4
 A  B  C  D
 1  2  3  4
 F  G  H  J去更新另外一個表x的值,有insert 的和update語句,字段一為主鍵值:
x表原來的值
字段1......字段4
 A  B  C  D
現在查詢出來的結果集更新表x,所以插入值如下:字段1......字段4
 1  2  3  4
 F  G  H  J
最后表x到結果集為
字段1......字段4
 A  B  C  D
 1  2  3  4
 F  G  H  J請問我該如何做。請寫出sql代碼或者delphi程式代碼。謝謝。不會的無擾!

解决方案 »

  1.   

    select * from x 
    union 
    select * from 第一个表 as aa where aa.字段1 not in (select 字段1 from x)一样?
    http://topic.csdn.net/u/20081007/12/692faad1-fc15-44a6-a59c-afc9bc9eda5b.html?seed=98615322
      

  2.   

    假设字段1为主键
    insert into 表x(字段1,字段2,字段3,字段4) select 字段1,字段2,字段3,字段4 from 源表 where 字段1 not in (select 字段1 form x)
      

  3.   

    insert into x (Field1,Field2,Field3,Field4) select Field1,Field2,Field3,Field4 from s_table where not exists (select * from x where x.Field1=Field1 and x.Field2=Field2 and x.Field3=Field3 and x.Field4=Field4)