它看起来像你的itemProperties表具有相同的“Product_ItemID”多个条目,而你正在寻找的东西,既是“BrandX”,并具有一定的“OtherProperty”一个不同的价值。为了处理这个问题,你可以使用TWICE表(如果你感兴趣的属性值更多,我会建议在Product_ItemProperties表上使用(Product_ItemID,Field,Value)对索引进行索引,以便对查询进行最佳优化。
例如,你正在寻找一个汽车品牌的“X”,其次,它是一个“蓝色”的车(不考虑目录组件)。
而且,在此查询通知,我给简化别名,并使用alias.field限定每个字段,因此不存在来自哪个字段的歧义。
外部WHERE子句是您的第一个条件,只会获得那些具有最小品牌名称fi并且它与您期望的值相匹配...从这些再次加入到产品物料属性表中,但对于您感兴趣的“其他”字段值及其值。
我不确定cataglog组件的位置,但我怀疑它来自产品表,并且应该调整IT别名。
SELECT
ByBrand.Product_ItemID,
P.NameOfProduct, (just an example to get this too)
FROM
Product_ItemProperties ByBrand
JOIN Product_Items P
ON ByBrand.Product_ItemID = P.Product_ItemID
JOIN Product_ItemProperties ByOtherField
ON ByBrand.Product_ItemID = ByOtherField.Product_ItemID
AND ByOtherField.Field = 'otherPropertyInterestedIn'
AND MATCH (ByOtherField.Value) against ('otherValueLookingFor' IN BOOLEAN MODE)
WHERE
ByBrand.Product_CatalogueID = 'someCatalogID' (or is this from product_items table)
AND ByBrand.Field = 'brandname'
AND MATCH (ByBrand.Value) against ('brandValueLookingFor' IN BOOLEAN MODE)
尝试把在查询前面EXPLAIN,看看有什么索引,而不是使用 – Tommassiov
你需要比查询,以分享更多 - 类似'EXPLAIN'的输出,表模式,记录的数量/关系等 – AgRizzo