0

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).

user1665355
  • 3,324
  • 8
  • 44
  • 84
  • What is `newtable`? You did not use `ThingName` in your query. Use `!=` or `<>` for [not-equal](https://dev.mysql.com/doc/refman/5.0/en/comparison-operators.html#operator_not-equal). – PM 77-1 Jun 15 '15 at 17:55
  • @PM77-1 Sorry was a typo... See the edited question. – user1665355 Jun 15 '15 at 17:57

1 Answers1

0

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
jurhas
  • 613
  • 1
  • 4
  • 12
  • That does not work... I basically want to check if a column have the same values in both tables, then do not insert, else insert. – user1665355 Jun 15 '15 at 20:01