我有两张表:表1
id name node
============
1 John 2277415921,2277415917,2277415929,2277415937
2 Jane 1098140458,1098146293,1098145477,1098140669
和表2
id nodeid name
==================
1 2277415937 Kirk
2 1098140669 Serena
当table2
中的nodeid
列的值位于table1
中的node
列中时,我需要从table2
更新table1
中的name
列
我试过这样做,但不起作用
UPDATE table1 t1
INNER JOIN table2 t2 ON t1.node LIKE '%'+t2.nodeid+'%'
SET t1.name = t2.name
你能告诉我怎么做吗? 谢谢
你有一个可怕的数据模型。 而在MySQL中,+
只表示加法。 您可以使用find_in_set()
:
UPDATE table1 t1 INNER JOIN
table2 t2
ON find_in_set(t2.node_id, t1.node)
SET t1.name = t2.name;
注您应该花精力修复table1
(每个节点一行,而不是字符串)。 不要花时间去理解数据模型。