Answer the question
In order to leave comments, you need to log in
SQL query for feature filter?
Good afternoon!
There is a table with product characteristics storage:
PropertyPivot
id
product_id
property_id
option_id
I actually have 2 questions. First, tell me what structure to use for multiple property values. Just create another such record in the database, with a different value?
And the second question, help with formulating an SQL query to filter by these characteristics. An example, if for example I choose Door - With a mirror and the outer color - Light, so that in the end only the door that is both with a mirror and white is selected, and not both.
Thanks in advance!
Answer the question
In order to leave comments, you need to log in
SELECT `p`.*
FROM `products` AS `p`
JOIN `PropertyPivot` AS `pp1` ON `pp1`.`product_id` = `p`.`id`
AND `pp1`.`property_id` = :p1_property AND `pp1`.`option_id` = :p1_value
JOIN `PropertyPivot` AS `pp2` ON `pp2`.`product_id` = `p`.`id`
AND `pp2`.`property_id` = :p2_property AND `pp2`.`option_id` = :p2_value
I can offer three options:
1) We do everything with one request, something like:
SELECT product_id
FROM PropertyPivot
WHERE property_id IN (...) AND option_id IN (...)
GROUP BY product_id
HAVING count(*) = количество параметров поиска
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question