Answer the question
In order to leave comments, you need to log in
How to write a query by multiple criteria in one column?
Good day to all! I have a table shown in the figure, I need to find the id of a product that would satisfy several requirements at once. For example: I need a spruce tree with parameters 200 10, i.e. the resulting product id will be equal to 3. I hope I explained myself clearly. So is it generally possible to write such a query in mysql?
Answer the question
In order to leave comments, you need to log in
Select idпродукта from
(
Select idпродукта from table where
(Значение = 200 and Idатрибута = 2 ) or
(Значение = 10 and Idатрибута = 3) or
(Значение = "Ель" and Idатрибута = 1)
) t1
group by idпродукта
having count(idпродукта)>2
Как вариант
select id from products as p
INNER JOIN productPropertys as type ON type.product_Id = p.id and type.value = 'ель'
INNER JOIN productPropertys as length ON length .product_Id = p.id and length .value = '200'
INNER JOIN productPropertys as someOtherProperty ON someOtherProperty .product_Id = p.id and someOtherProperty .value = '10'
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question