与WHERE的mysql INNER JOIN。需要了解代码的作用

时间:2013-10-12 07:13:33

标签: mysql

2_1_journal

TransactionPartnerName 
-----------------------
 name 1
 name 2
 name 3

2_1_transactionpartners

CompanyName   |  PreviousCompanyName
------------------------------------
 name 1       |   
 name 2       |   
 name 3       |  name 2

例如,想要将name 1更改为name 11

首先在表2_1_transactionpartners中复制来自name 1的{​​{1}}并将其粘贴到CompanyName

PreviousCompanyName中的下一个需要将2_1_journal更改为name 1。我认为:将name 11更改为TransactionPartnerName,其中CompanyName等于TransactionPartnerName。但我不希望在表PreviousCompanyName中将2_1_journal更改为name 2,因为只需将({1}}更改为name 3

这是我的代码。发现没有错误。但是想确定代码是什么

name 1

name 11 = UPDATE 2_1_journal INNER JOIN 2_1_transactionpartners ON (2_1_journal.TransactionPartnerName = 2_1_transactionpartners.PreviousCompanyName) SET 2_1_journal.TransactionPartnerName = 2_1_transactionpartners.CompanyName WHERE 2_1_transactionpartners.CompanyName = ?

了解代码更新?并将name 11复制到2_1_journal,如果CompanyName等于TransactionPartnerNameCompanyName等于name 11 }

我说错了吗?可能有更好的方法达到目的吗?

1 个答案:

答案 0 :(得分:1)

UPDATE IGNORE 2_1_transactionpartners, 2_1_journal 
SET 2_1_journal.TransactionPartnerName = 2_1_transactionpartners.CompanyName
WHERE 2_1_journal.TransactionPartnerName =  
2_1_transactionpartners.PreviousCompanyName
AND 2_1_transactionpartners.CompanyName = ?