All pastes #2051449 Raw Edit

Unnamed

public text v1 · immutable
#2051449 ·published 2011-04-28 07:26 UTC
rendered paste body
      Table 1 PK = f1,f2,f3,f4 (123,2345,1,2)
      | 123 | 2345 | 1 | 2 | 23456 | 45 | 1111 | "2011-01-01 10:01:01" |

      Table 2 PK = f1,f2,f3,f4  (123,2345,1,2)

      | 123 | 2345 | 1 | 2 | 999999 | 12 | 3333 | "2011-02-01 12:01:01" |

     INSERT INTO table1 SELECT * from table2 ON DUPLICATE KEY UPDATE
              f5 = IF(table1.f5 < VALUES(f5),VALUES(f5),table1.f5),
              f6 = IF(table1.f5 < VALUES(f5),VALUES(s6),table1.s6),
              f7 = IF(table1.f5 < VALUES(f5),VALUES(f7),table1.f7),
              ts = IF(table1.f5 < VALUES(f5),VALUES(ts),table1.ts)
      ;
 

      Table 1 now
      | 123 | 2345 | 1 | 2 | 999999 | 45 | 1111 | "2011-01-01 10:01:01" |
      BUT I want Table 1 to have

      | 123 | 2345 | 1 | 2 | 999999 | 12 | 3333 | "2011-02-01 12:01:01" |