MySQL search products with their attributes

馋奶兔 提交于 2019-12-01 08:04:54

You need to join with product_filters separately for each attribute:

SELECT DISTINCT products.*  
FROM products
JOIN product_filters AS f1 ON f1.product_id=products.id
JOIN product_filters AS f2 ON f2.product_id=products.id
WHERE ( f1.attribute_id=1 and f1.filter_id in (1,2) )
AND ( f2.attribute_id=3 and f2.filter_id in (6) )

DEMO

Your version tried to find a single row in product_filters that has both attribute IDs, which isn't possible.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!