繁体   English   中英

在MySQL的where子句中使用多个表更新查询

[英]Update query with multiple table in where clause in MySql

我想在表lp_term_relationships中设置term_taxonomy_id ='4',其中post_title

就像'%Apple%'。 post_title在表lp_posts 但这给了我语法错误。 有帮助吗??

这是我的查询:

Update `lp_term_relationships`     
set `lp_term_relationships`.`term_taxonomy_id` = '4'   
FROM `lp_term_relationships`, `lp_posts `  
WHERE  `lp_posts`.`post_title` Like '%Apple%';

您需要在此处执行适当的加入。 您还没有提到链接它们的外键关系...也将外键关系添加到where子句中。您的最终查询将如下所示:

update table1, table2 
set table1.col=1
where table1.id= table2.fkey_id
and table1.column2 like '%APPLE%'

您需要编写正确的列名和链接表的关系。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM