-2

Today i want to write a query to automatically copy the value of one cell to another in different tables comparing the equality of ids... so i have x_content1 table with id1 column and title1 column, i need to copy title1 column into x_content2 table title2 column comparing id1 with id2

UPDATE x_content2
SET x_content2.title2 = x_content1.title1
WHERE x_content1.id1 = x_content2.id2

Please, help! =)

  • What's this??? The statement won't even run. Learn to do some research. Learn to read documentation. This question shows no effort at all!!!! – Eric Apr 03 '18 at 15:53
  • thanks for the answer, @Eric very useful! This is what i understood from the answers on another questions on stackoverflow.com and tried to give an example of what i want to build. for several hours i tried to find in the documentation the answer for my question, and i couldn't. thats why im asking here. here for example [https://stackoverflow.com/a/19541555/6715731](https://stackoverflow.com/a/19541555/6715731) – Alex Fedorin Apr 03 '18 at 16:57
  • Do `SELECT` first to make sure you get all the necessary info. Then convert it to `UPDATE`. – Eric Apr 03 '18 at 17:59
  • Show your `SELECT`. – Eric Apr 03 '18 at 17:59
  • Hey, @Eric! I've updated the query as in the tutorial here [http://www.mysqltutorial.org/mysql-update-join/](http://www.mysqltutorial.org/mysql-update-join/) is it correct now? – Alex Fedorin Apr 04 '18 at 13:07
  • You miss the `JOIN` to the other table. – Eric Apr 04 '18 at 15:41

1 Answers1

0

With the JOIN. See if this works or not.

UPDATE x_content2
JOIN x_content1 ON x_content1.id1 = x_content2.id2
SET x_content2.title2 = x_content1.title1
Eric
  • 3,165
  • 1
  • 19
  • 25