开发者

How use table column as string in a multi-table update in MySQL?

开发者 https://www.devze.com 2023-02-15 14:27 出处:网络
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\"

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

0

精彩评论

暂无评论...
验证码 换一张
取 消