嘿伙计们,我想学习如何从多对多数据库进行查询。这是具有三个表和一个具有三个外键的多对多表的数据库示例。您将如何在st_glowne_others
表上执行 SELECT 语句?
例如,如果我想从“st_components”表中选择所有可能的结果,该表与“st_glowne”表中名称列的特定值和“st_pages”表中名称列的特定值链接。提前致谢!。
表格1
CREATE TABLE `st_glowne` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(50) COLLATE utf8_polish_ci NOT NULL,
`location` varchar(50) COLLATE utf8_polish_ci NOT NULL DEFAULT './',
PRIMARY KEY (`name`),
KEY `id` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8 COLLATE=utf8_polish_ci
表2
CREATE TABLE `st_pages` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(50) COLLATE utf8_polish_ci NOT NULL,
`filelocation` varchar(50) COLLATE utf8_polish_ci NOT NULL DEFAULT 'pages/',
PRIMARY KEY (`name`),
KEY `id` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8 COLLATE=utf8_polish_c
表3
CREATE TABLE `st_components` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(50) COLLATE utf8_polish_ci NOT NULL,
`location` varchar(100) COLLATE utf8_polish_ci NOT NULL DEFAULT 'components/',
PRIMARY KEY (`name`),
KEY `id` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 COLLATE=utf8_polish_ci
这是我们要查询的表:
CREATE TABLE `st_glowne_others` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`st_glowne` varchar(50) COLLATE utf8_polish_ci NOT NULL,
`st_pages` varchar(50) COLLATE utf8_polish_ci NOT NULL,
`st_components` varchar(50) COLLATE utf8_polish_ci NOT NULL,
PRIMARY KEY (`id`),
KEY `id` (`id`),
KEY `st_glowne` (`st_glowne`),
KEY `st_pages` (`st_pages`),
KEY `st_components` (`st_components`),
KEY `st_components_2` (`st_components`),
CONSTRAINT `st_glowne_others_ibfk_3` FOREIGN KEY (`st_components`) REFERENCES `st_components` (`name`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `st_glowne_others_ibfk_1` FOREIGN KEY (`st_glowne`) REFERENCES `st_glowne` (`name`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `st_glowne_others_ibfk_2` FOREIGN KEY (`st_pages`) REFERENCES `st_pages` (`name`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 COLLATE=utf8_polish_ci
你能告诉我如何从中查询吗?非常感谢 !