table 1 table 2
+---------+------------+ +---------+------------+
| post_id | meta_value | | ID | post_title |
+---------|------------+ +---------|------------+
| 1 | value_a | | 1 | title_abc |
+---------|------------+ +---------|------------+
| 2 | value_b | | 2 | title_xyh |
+---------|------------+ +---------|------------+
| 3 | value_c | | 3 | title_jer |
+---------|------------+ +---------|------------+
| ..... | ......... | | ..... | ....... |
+---------|------------+ +---------|------------+
| 999 | value_xyzw | | 999 | title_bhw |
+---------|------------+ +---------|------------+
我有2张桌子。我尝试将post_title
(表2)中的记录替换为meta_value
{表1)。
示例:
value_a
替换title_abc
value_b
替换title_xyh
value_c
替换title_jer
............
等
谢谢!
答案 0 :(得分:1)
您想要update
join
:
update table1 t1 join
table2 t2
on t1.post_id = t2.id
set t1.meta_value = t2.post_title;
答案 1 :(得分:1)
UPDATE table1, table2 SET table1.metavalue = table2.post_title
WHERE table1.id = table2.id