Insert and update based on comparison of fields between two tables

55 views Asked by At

I would like to Insert a record in a table if a variable is not equal the same column in another table. Something like:

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

So CoolThing is a field (column).

1

There are 1 answers

1
jurhas On

Try with:

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