E
E
Evgeny Konin2018-05-16 18:41:32
MySQL
Evgeny Konin, 2018-05-16 18:41:32

Merge two tables by id (MySql)?

Hello, there are two tables (tb1, tb2) with a joining column "id". It is necessary to transfer the "content" column from one table "tb1" to the table "tb2" according to the matching id column.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
K
Kairat Ubukulov, 2018-05-17
@ExEnSpooT

You really have a syntax error.

UPDATE wp_posts
JOIN modx_site_content ON modx_site_content.id = wp_posts.id
SET wp_posts.content = modx_site_content.content

Read more here.
www.mysqltutorial.org/mysql-update-join

V
Vasya, 2018-05-16
@haramba

select t2.*, t1.content
from tb2 t2 left join tb1 t1 on t2.id = t1.id

E
Evgeny Konin, 2018-05-17
@ExEnSpooT

The request passes, but no changes are observed. Found another option

UPDATE wp_posts
SET wp_posts.content = modx_site_content.content
FROM modx_site_content JOIN wp_posts ON modx_site_content.id = wp_posts.id

Writes:
#1064 - You have an error in your request. Check the documentation for your version of MySQL for the correct syntax around 'FROM modx_site_content JOIN wp_posts ON modx_site_content.id = wp_posts.id' on line 3

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question