P
P
polynuc2018-06-24 14:25:29
MySQL
polynuc, 2018-06-24 14:25:29

How to write a query for a filter?

There is a site filter.
Filters are grouped into groups, visually displayed how it should work:
5b2f7e906ef1c586638160.jpeg
that is, logically, there should be such a condition:
WHERE (shop_products_filter.filter_id=14 OR shop_products_filter.filter_id=15)
AND (shop_products_filter.filter_id=18 OR shop_products_filter.filter_id=19)
The entire request

SELECT *
FROM products
LEFT JOIN shop_products_filter ON products.id=shop_products_filter.product_id
WHERE (shop_products_filter.filter_id=14 OR shop_products_filter.filter_id=15) 
AND (shop_products_filter.filter_id=18 OR shop_products_filter.filter_id=19)

But the request doesn't return anything.
If you just write WHERE (shop_products_filter.filter_id=14 OR shop_products_filter.filter_id=15) or WHERE (shop_products_filter.filter_id=18 OR shop_products_filter.filter_id=19), then everything works.
There are no problems with the architecture of the tables itself, apparently I am compiling the query incorrectly

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question