简体   繁体   English

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

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

I want to set the term_taxonomy_id = '4' in table lp_term_relationships where post_title 我想在表lp_term_relationships中设置term_taxonomy_id ='4',其中post_title

Like '%Apple%'. 就像'%Apple%'。 Column post_title is in the table lp_posts . post_title在表lp_posts But it is giving me the syntax error. 但这给了我语法错误。 Any help ?? 有帮助吗??

This is my Query: 这是我的查询:

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%';

you need to perform a proper join here. 您需要在此处执行适当的加入。 You have not mentioned the foreign key relation that links both of them...Add the foreign key relationship in the where clause as well..Your final query would be something like this: 您还没有提到链接它们的外键关系...也将外键关系添加到where子句中。您的最终查询将如下所示:

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

you need to write the correct column names and relationship that links the tables. 您需要编写正确的列名和链接表的关系。

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

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