1

这是两个 SugarCRM 表之间的更新查询,两个 INNODB 看起来都很简单,但是运行时它不会更新记录

查询执行正常,0 行受影响

我们已经运行了一个选择查询以确保我们在 ids 上匹配 还尝试过更新...选择变体

已经检查了两个表的索引 - 存在并且显然 OK 有没有人有任何提示。

UPDATE accounts new LEFT join  accounts_old old
ON (new.id = old.id) 
SET new.billing_address_country = old.billing_address_country

感谢您的任何想法。

4

1 回答 1

1

除非伴随 WHERE... IS NULL,否则 UPDATE 查询中的 OUTER JOIN 极为罕见。你确定那是你想要的吗?

除此之外,这个查询没有任何问题......

DROP TABLE IF EXISTS accounts;

CREATE TABLE accounts(id INT NOT NULL PRIMARY KEY,billing_address_county VARCHAR(40) NOT NULL);

DROP TABLE IF EXISTS accounts_old;

CREATE TABLE accounts_old(id INT NOT NULL PRIMARY KEY,billing_address_county VARCHAR(40) NOT NULL);

INSERT INTO accounts VALUES (1,'Hale County');
INSERT INTO accounts VALUES (2,'Perry County');

INSERT INTO accounts_old VALUES (1,'Hale County');
INSERT INTO accounts_old VALUES (2,'Tuscaloosa County');


UPDATE accounts new 
  JOIN accounts_old old 
    ON old.id = new.id 
   SET new.billing_address_county = old.billing_address_county;

Query OK, 1 row affected (0.01 sec)
   Rows matched: 2  Changed: 1  Warnings: 0

   mysql> SELECT * FROM accounts;
   +----+------------------------+
   | id | billing_address_county |
   +----+------------------------+
   |  1 | Hale County            |
   |  2 | Tuscaloosa County      |
   +----+------------------------+
   2 rows in set (0.00 sec)

mysql>
于 2013-07-10T23:36:30.460 回答