0

I've run into a problem where I'd like to copy data between columns based on a condition from a related table. Looking at the top answer from eglasius on this similar problem similar problem I came up with this solution:

UPDATE table1 SET table1.column2 = table2.column1 
FROM table1 NATURAL JOIN table2 
WHERE table2.column1 = "myCondition"

This query gave me a syntax error beginning at FROM although replacing the UPDATE clause with a SELECT seemed to yield no problems.

Community
  • 1
  • 1
2NinerRomeo
  • 2,687
  • 4
  • 29
  • 35

1 Answers1

0

It seems that in the case of an UPDATE mySQL appears to dislike a FROM syntax. I had good success moving the join to the front of the query, following it with the JOIN and finally the WHERE condition, like this:

UPDATE table1 NATURAL JOIN table2
SET table1.column2 = table1.column1
WHERE table2.column1 = "myCondition"
2NinerRomeo
  • 2,687
  • 4
  • 29
  • 35
  • I owe this solution in part to @Eric for his answer to [this question](http://stackoverflow.com/questions/3818512/sql-update-one-column-from-another-column-in-another-table) – 2NinerRomeo Mar 04 '15 at 21:35