0

桌子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 1CompanyNamePreviousCompanyName

接下来需要在表中2_1_journal更改name 1name 11。我认为:更改TransactionPartnerNameCompanyNamewhereTransactionPartnerName等于PreviousCompanyName。但我不想在表中2_1_journal更改name 2为,name 3因为只想(给出命令)更改name 1name 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并复制CompanyNameTransactionPartnerNameifCompanyName等于name 11TransactionPartnerName等于PreviousCompanyName

我对么?可能有更好的方法来达到目标​​吗?

4

1 回答 1

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 = ?
于 2013-10-12T07:35:38.063 回答