[英]Replace multiple values - MySQL
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张桌子。 我尝试用meta_value
{表1)替换post_title
(表2)中的记录。
例:
value_a
替换title_abc
value_b
替换title_xyh
value_c
替换title_jer
............
等等
谢谢!
你想要一个update
与join
:
update table1 t1 join
table2 t2
on t1.post_id = t2.id
set t1.meta_value = t2.post_title;
UPDATE table1, table2 SET table1.metavalue = table2.post_title
WHERE table1.id = table2.id
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.