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」。
任何線索?
「UPDATE」中*實際*改變了多少行,即在'UPDATE'語句出現後有不同的值?根據[文檔](http://dev.mysql.com/doc/refman/5.0/en/update.html),「UPDATE返回實際更改的行數。」 – mellamokb
請勿使用隱式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