Y
Y
Yazis2021-01-19 13:40:49
MySQL
Yazis, 2021-01-19 13:40:49

What query to write to transfer data from one table to another with the condition of matching keys?

There are 2 tables. In one and in the second there is a glav_id field, they coincide with each other.
6006b652031b9350665933.png
6006b6635b247931057224.png

I need to transfer the values ​​of the region field from Table 2 to Table 1 in the region field in accordance with the glav_id field. You need to create a SQL query.
Something like this: UPDATE `tabl_1` SET `region`= (SELECT `region` FROM `tabl_2` WHERE `tabl_1`(`glav_id`) = `tabl_2`(`glav_id`)) but this is not a valid query

Please help! Thanks in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
mahmudchon, 2021-01-19
@Yazis

UPDATE
  `tabl_1`
INNER JOIN
  `tabl_2`
ON
  `tabl_2`.`glav_id` = `tabl_1`.`glav_id`
SET
  `tabl_1`.`region` = `tabl_2`.`region`

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question