T
T
topalek2021-05-23 20:18:51
JavaScript
topalek, 2021-05-23 20:18:51

How to create the right lookup query?

There are 3 tables product, property and product_property. products are related to property through the product_property intermediate table.
How to choose the right products from product that would match multiple property.id?

SELECT * FROM `product`
left join `product_property` ON `product_property`.product_id=`product`.id
WHERE (product.category_id=4625415)
  AND (product_property.property_id=20)
  AND (product_property.property_id=1)
 AND (product_property.property_id=5)


In general, you need to implement filtering products by characteristics.
tell me how to do it.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
sergiysan, 2018-12-24
@o_may

Perhaps your script is included in the head and simply does not see h4. Because the script is quite working

A
Akina, 2021-05-23
@Akina

Sample.

SELECT product.id
FROM product
INNER JOIN product_property
INNER JOIN property
WHERE property.value IN ( {values list} )
GROUP BY product.id
HAVING COUNT(DISTINCT property.value) = {distinct values count}

You will add binding conditions and additional restrictions yourself.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question