2011-10-10 96 views
0

這裏的數據:SELECT返回的數據,但UPDATE給受影響的行:0

CREATE TABLE `Charlies_Sierra_Papa` (
    `Mike` int(5) default NULL, 
    `cpf` char(11) default NULL, 
    `idFoxtrot` int(3) default NULL, 

) ENGINE=MyISAM AUTO_INCREMENT=254098 DEFAULT CHARSET=utf8; 

INSERT INTO `Charlies_Sierra_Papa` VALUES ('1', '12345678910', '12'); 
INSERT INTO `Charlies_Sierra_Papa` VALUES ('2', '11121314157', '12'); 
INSERT INTO `Charlies_Sierra_Papa` VALUES ('3', '57585960610', '12'); 


CREATE TABLE `Charlies` (
    `idCharlie` int(20) NOT NULL auto_increment, 
    `cpf` varchar(11) NOT NULL default '' 
    PRIMARY KEY (`idCharlie`), 
    UNIQUE KEY `cpf` (`cpf`), 
    UNIQUE KEY `idCharlie` (`idCharlie`), 
) ENGINE=MyISAM AUTO_INCREMENT=264670 DEFAULT CHARSET=latin1; 

INSERT INTO `Charlies` VALUES ('1', '12345678910'); 
INSERT INTO `Charlies` VALUES ('2', '11121314157'); 
INSERT INTO `Charlies` VALUES ('3', '57585960610'); 


CREATE TABLE `Mike` (
    `Mike` int(5) unsigned zerofill NOT NULL auto_increment, 
    `idCharlie` int(11) NOT NULL default '0', 
    PRIMARY KEY (`Mike`), 
    UNIQUE KEY `idCharlie` (`idCharlie`) 
) ENGINE=MyISAM AUTO_INCREMENT=12043 DEFAULT CHARSET=latin1; 

INSERT INTO `Mike` VALUES ('00001', '51214'); 
INSERT INTO `Mike` VALUES ('00002', '174135'); 
INSERT INTO `Mike` VALUES ('00003', '203553'); 

這裏是SELECT和UPDATE:

UPDATE Charlies_Sierra_Papa AS csp, Charlies AS Cha, Mike_oc AS Mik 
SET csp.cpf = cast(Cha.cpf AS char(11)) 
WHERE csp.cpf = Cha.cpf 
AND Cha.idCharlie = Mik.idCharlie 
AND csp.Mike = Mik.Mike 
AND csp.idFoxtrot = 16 


SELECT * FROM Charlies_Sierra_Papa AS csp, Charlies AS Cha, Mike_oc AS Mik 
/*SET csp.cpf = cast(Cha.cpf AS char(11))*/ 
WHERE csp.cpf = Cha.cpf 
AND Cha.idCharlie = Mik.idCharlie 
AND csp.Mike = Mik.Mike 
AND csp.idFoxtrot = 16 

我的問題是:SELECT返回預期值,但是當我運行它時,UPDATE給了我一個煩人的「Affected rows:0」。

任何線索?

+0

「UPDATE」中*實際*改變了多少行,即在'UPDATE'語句出現後有不同的值?根據[文檔](http://dev.mysql.com/doc/refman/5.0/en/update.html),「UPDATE返回實際更改的行數。」 – mellamokb

+0

請勿使用隱式SQL連接,使用顯式連接語法:'UPDATE Charlies_Sierra_Papa csp INNER JOIN Charlies Cha ON(csp.cpf = Cha.cpf)INNER JOIN Mike_oc Mik ON(Cha.idCharlie = Mik.idCharlie AND csp.Mike = Mik.Mike) SET csp.cpf = cast(Cha.cpf AS char(11)) WHERE csp.idFoxtrot = 16' – Johan

回答

0

這是一個微不足道的錯誤:

我試圖更新csp.cpf = Cha.cpf 但我還搭售csp.cpf = Cha.cpf 因此,沒有行更新,並沒有雪茄。

相關問題