U
U
Ultraice2016-11-08 15:20:09
MySQL
Ultraice, 2016-11-08 15:20:09

How to make a selection from a table where the values ​​fall under several parameters?

There are two tables:
1. product
id table | title | price | date1
| title1 | 100 | date1
2 | title2 | 200 | date2
3 | title3 | 300 | date3
2. table with product parameters
id | param_id | value | goods_id
1 | 10 | value1 | 1
2 | 11 | value2 | 1
3 | 10 | value1 | 2
4 | 10 | value3 | 3
Is it possible to make a selection of goods with one request that fall under certain conditions - let's say the cost of the goods is more than 50 and the goods must have parameters param_id = "10" with value = "value1" and param_id = "11" with value = "value2"
In a similar question, I found a solution, but when you need to find products
the cost of the product is greater than 50
and the product has param 10 = value1 or param 10 = value3
and param_id = "11" with value = "value2"

SELECT g.* 
FROM table_goods g
    JOIN table_goods_params p1 ON p1.goods_id = g.id AND p1.param_id = 10 AND p1.value = "значение1"
    JOIN table_goods_params p2 ON p2.goods_id = g.id AND p2.param_id = 11 AND p2.value = "значение2"
WHERE g.price > '50'

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
romy4, 2016-11-08
@Ultraice

something like that

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question