SELECT返回数据,但UPDATE给出受影响的行:0

时间:2011-10-10 18:21:17

标签: mysql sql-update

以下是数据:

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给了我一个恼人的“受影响的行:0”。

任何线索?

1 个答案:

答案 0 :(得分:0)

这是一个微不足道的错误:

我正在尝试更新csp.cpf = Cha.cpf 但我也在追csp.cpf = Cha.cpf 所以,没有行更新,没有雪茄。