根据两个表之间的字段比较插入和更新

时间:2015-06-15 17:44:08

标签: mysql sql-insert dml

我想在表if中插入记录,变量不等于另一个表中的同一列。类似的东西:

        Insert IGNORE INTO newtable
        SELECT * FROM oldtable
        WHERE url="www.theurl.com/1" AND 
              (field CoolThing from newtable != CoolThing from oldtable)

所以CoolThing是一个字段(列)。

1 个答案:

答案 0 :(得分:0)

尝试:

Insert IGNORE INTO newdata 
    SELECT o.* /* this is allowed only if the count and order of the
 columns  of the two tables are exactly the same */
   FROM olddata o left join 
    newdata n on n.coolthing=o.coolthing
    WHERE o.url="www.theurl.com/1" AND o.coolthing is NULL
相关问题