0
我有这3个表:恩如何获得每个视频的所有子类别中的MySQL
CREATE TABLE `subcategories` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(45) DEFAULT NULL,
`categories_id` int(11) NOT NULL,
PRIMARY KEY (`id`),
KEY `fk_subcategories_categories1_idx` (`categories_id`),
CONSTRAINT `fk_subcategories_categories1` FOREIGN KEY (`categories_id`) REFERENCES `categories` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=71 DEFAULT CHARSET=utf8;
CREATE TABLE `videos` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`brightcove_id` varchar(45) DEFAULT NULL,
`video_stillUrl` text,
`video_thumbnailURL` text,
`video_playsTotal` varchar(45) DEFAULT NULL,
`establishments_id` int(11) NOT NULL,
PRIMARY KEY (`id`),
KEY `fk_videos_establishments1_idx` (`establishments_id`),
CONSTRAINT `fk_videos_establishments1` FOREIGN KEY (`establishments_id`) REFERENCES `establishments` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=220 DEFAULT CHARSET=utf8;
CREATE TABLE `subcategories_videos` (
`subcategories_id` int(11) NOT NULL,
`videos_id` int(11) NOT NULL,
PRIMARY KEY (`subcategories_id`,`videos_id`),
KEY `fk_subcategories_videos_subcategories1_idx` (`subcategories_id`),
KEY `fk_subcategories_videos_videos1_idx` (`videos_id`),
CONSTRAINT `fk_subcategories_videos_subcategories1` FOREIGN KEY (`subcategories_id`) REFERENCES `subcategories` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT `fk_subcategories_videos_videos1` FOREIGN KEY (`videos_id`) REFERENCES `videos` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
,我想知道,我怎么会碰到一些在确定的子类别中的影片,例如:
select * from subcategories_videos where subcategories_id in(62,61);
在这里我得到的带有编号62和61,但类别对应的所有影片我怎样才能得到一个视频是在两个子类别,像这样:
select * from subcategories_videos where videos_id=193
这里它将通过视频ID获取子类别,但我如何才能对所有记录执行此操作?非常感谢!
你救我的命我的朋友,我真的很感谢你的帮助,非常感谢! – 2014-11-01 20:18:28