【发布时间】:2014-02-14 09:18:34
【问题描述】:
我有以下 DDL...
CREATE TABLE IF NOT EXISTS `product` (
`id_product` int(10),
`id_manufacturer` int(10)
);
INSERT INTO `product` (`id_product`, `id_manufacturer`) VALUES
(1,1),
(2,1),
(3,2),
(4,1),
(5,2);
CREATE TABLE IF NOT EXISTS `feature_product` (
`id_feature` int(10),
`id_product` int(10),
`id_feature_value` int(10)
);
INSERT INTO `feature_product` (`id_feature`, `id_product`, `id_feature_value`) VALUES
(5, 1, 9),
(5, 2, 9),
(5, 3, 10),
(5, 4, 10),
(7, 5, 10);
http://sqlfiddle.com/#!2/cbe05/1/0
您能否解释一下,我如何才能获得 - 具有相同制造商和相同 Feature_value 的所有产品?
现在(在项目中)我使用 2 个额外的 SELECT(用于获取 id_manufacturer 和 id_feature_value),但也许有更正确(和快速)的方法?
感谢您的宝贵时间,对不起我的英语)
我也需要看到这样的结果:
id_product |
-----------|
1 |
2 |
只有这两种产品具有相同的制造商和(同时)相同的特征值
【问题讨论】:
-
想要的结果是什么样的?
-
已添加,感谢您对编辑的帮助
标签: mysql sql optimization join inner-join