请帮助关于以下mysql查询的mi, 我有一个表格主页,如下所示:
id phone phone2
======================================
1 98998 | 58877
2 98998 | 58877
3 98998
我想通过电话栏更新phone2并尝试使用以下子查询,但我没有得到所需的结果,如果有可能请帮助获得结果:
update main a
set a.phone2 = (SELECT substring_index(b.phone,'|',-1)
FROM main b
where b.phone like '%|%' and where a.id=b.id)
答案 0 :(得分:1)
试试这个:
UPDATE main a
INNER JOIN (SELECT id, substring_index(phone,'|',-1) AS phone
FROM main
WHERE phone LIKE '%|%'
) b
ON a.id = b.id
SET a.phone2 = b.phone;