例如:當我用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)
      

  2.   

    select * from x 
    union 
    select * from 第一个表 as aa where aa.字段1 not in (select 字段1 from x)
      

  3.   


      Select A,B,C,D from x 
      union 
      Select A.A,A.B,A.C,A.D From Tabel1 AS A Where A.A not in (Select A from x)
      

  4.   

    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)