Let's say i've in a mysql db:
- table called "user" with "id_user" and "extrafield"
- table called "connection" with "id_user" and "id_content"
- table called "content" with "id_content" and "user_content"
Into "user_content" i've multiple fields inside like:
<br />::field1::fieldvalue::/field1::&l开发者_运维知识库t;br />::field2::fieldvalue::/field2::<br />
What's the best query to copy "field2" value from "content" inside "extrafield" in "user" ?
Thank you
SET @user = 1;
UPDATE content
SET content.user_content = replace(content.user_content, 'field2',
(SELECT extrafield FROM user WHERE id_user = @user))
WHERE content.id_content 1;
This query will do the replace for you. You have to join the tables appropriately though.
精彩评论