mysqldeletein_Mysqldeletefromwhereidin(lect。。。comments_closure
SET FOREIGN_KEY_CHECKS=0;
奇异性-- ----------------------------
-- Table structure for comments_closure
-- ----------------------------
DROP TABLE IF EXISTS `comments_closure`;创新事例
拳皇图片CREATE TABLE `comments_closure` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`author` varchar(255) NOT NULL,
`comment` text NOT NULL,
qq单向好友PRIMARY KEY (`id`)
)
ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of comments_closure
-- ----------------------------
INSERT INTO `comments_closure` VALUES ('1', 'Fran', '这个Bug的成因是什么?');可乐喝多了有什么危害
INSERT INTO `comments_closure` VALUES ('2', 'Ollie', '我觉得是⼀个空指针');
INSERT INTO `comments_closure` VALUES ('3', 'Fran', '不,我查过了');
INSERT INTO `comments_closure` VALUES ('4', 'Kukla', '我们需要查⽆效输⼊');
INSERT INTO `comments_closure` VALUES ('5', 'Ollie', '是的,那是⼀个问题');
INSERT INTO `comments_closure` VALUES ('6', 'Fran', '好, 查⼀下吧');
INSERT INTO `comments_closure` VALUES ('7', 'Kukla', '解决了');
INSERT INTO `comments_closure` VALUES ('8', 'Kukla', '那必然是个问题');
treepaths
SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
-- Table structure for treepaths
-- ----------------------------
DROP TABLE IF EXISTS `treepaths`;
CREATE TABLE `treepaths` (
`ancestor` int(10) unsigned NOT NULL,
百度网页翻译`descendant` int(10) unsigned NOT NULL,
PRIMARY KEY (`ancestor`,`descendant`),
KEY `descendant` (`descendant`),
CONSTRAINT `treepaths_ibfk_1` FOREIGN KEY (`descendant`) REFERENCES `comments_closure` (`id`) ON DELETE CASCADE,
CONSTRAINT `treepaths_ibfk_2` FOREIGN KEY (`ancestor`) REFERENCES `comments_closure` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of treepaths
-- ----------------------------
INSERT INTO `treepaths` VALUES ('1', '1');
INSERT INTO `treepaths` VALUES ('1', '2');
INSERT INTO `treepaths` VALUES ('1', '3');
INSERT INTO `treepaths` VALUES ('1', '4');
INSERT INTO `treepaths` VALUES ('1', '5');
INSERT INTO `treepaths` VALUES ('1', '6');
INSERT INTO `treepaths` VALUES ('1', '7');
INSERT INTO `treepaths` VALUES ('1', '8');
INSERT INTO `treepaths` VALUES ('2', '2');
INSERT INTO `treepaths` VALUES ('2', '3');乳清蛋白粉的功效与作用
INSERT INTO `treepaths` VALUES ('3', '3');
INSERT INTO `treepaths` VALUES ('4', '4');
INSERT INTO `treepaths` VALUES ('4', '5');
INSERT INTO `treepaths` VALUES ('4', '6');
INSERT INTO `treepaths` VALUES ('4', '7');
INSERT INTO `treepaths` VALUES ('4', '8');炒豆角丝
INSERT INTO `treepaths` VALUES ('5', '5');
INSERT INTO `treepaths` VALUES ('5', '8');
INSERT INTO `treepaths` VALUES ('6', '6');
INSERT INTO `treepaths` VALUES ('6', '7');
INSERT INTO `treepaths` VALUES ('7', '7');
INSERT INTO `treepaths` VALUES ('8', '8');
SELECT descendant FROM treepaths WHERE ancestor=4
查出的结果是:
我想删除评论4和所有他的⼦评论
DELETE FROM comments_closure WHERE id IN(SELECT descendant FROM treepaths WHERE ancestor=4)这样删的话只能删除 IN 条件中的第⼀条记录 也就是只能删除记录4
如果这样
DELETE FROM comments_closure WHERE id IN(4,5,6,7,8)
则可以全部删掉 .
不明⽩什么原因啊.请教各位.