Here's the data:
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 DE开发者_JAVA百科FAULT 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');
And here are the SELECT and the 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
my problem is: the SELECT returns the expected values, but the UPDATE gives me an annoying "Affected rows: 0" when I run it.
Any clues?
It's a trivial error:
I'm trying to UPDATE csp.cpf = Cha.cpf but I'm also tying csp.cpf = Cha.cpf so, no rows updated and no cigar.
精彩评论