mysql:使用Join更新

时间:2014-03-31 13:16:53

标签: mysql

company contains id,company_name

company_alias contains id,company_id,company_alias

company_rawdata contains id,complaint descrption,company_match

我正在尝试使用company_name更新company_match,其中company descrption包含别名。

 update company_rawdata cr inner join company c on c.company_name 
 like concat('',cr.complaint_descrption,'') set cr.matched_company = c.company_name

2 个答案:

答案 0 :(得分:0)

UPDATE company_rawdata r
INNER JOIN company_alias a ON a.company_alias = r.description
INNER JOIN company c ON c.id = a.company_id
SET r.company_match = c.company_name 

或者,如果a.company_alias包含在a.company_alias中的某个地方,则以下内容:

UPDATE company_rawdata r
INNER JOIN company_alias a ON a.company_alias LIKE CONCAT('%', r.description, '%')
INNER JOIN company c ON c.id = a.company_id
SET r.company_match = c.company_name 

答案 1 :(得分:0)

试试:

 UPDATE company c
 INNER JOIN company_alias a ON a.company_id = c.id
 INNER JOIN company_rawdata r ON a.company_alias = r.company_match
 SET r.company_match = c.company_name