How use table column as string in a multi-table update in MySQL?
Two tables,
agent(agent_id, agent_real_name, .....)
blog(blog_id, blog_agent_id, blog_name, ...)
Now I want to set the blog_name as agent_real_name + "'s blog" I used following SQL sente开发者_StackOverflownce but failed,
update blog, agent set blog_name = agent_real_name '\'s blog' where agent_id = 31
PS: 31 is the id of a agent
What's wrong?
Thanks.
UPDATE blog b INNER JOIN agent a
ON a.agent_id = b.blog_agent_id
SET b.blog_name = CONCAT(a.agent_real_name,'\'s blog')
WHERE a.agent_id = 31
try to use:
update blog, agent set blog_name = concat(agent_real_name, '\'s blog') where agent_id = 31
精彩评论