B
B
Bamp2016-08-17 11:35:15
MySQL
Bamp, 2016-08-17 11:35:15

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?
7946befc563c42b7bb90937e1b7c5d59.jpg

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alex, 2016-08-17
@Bamp

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

Дмитрий Ковальский, 2016-08-17
@dmitryKovalskiy

Как вариант

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 question

Ask a Question

731 491 924 answers to any question