OneToMany relationship
I am not a pro with mysql so I guess there is some simple solution for my problem. Basically:
how can check each row individually if it contains a certain values (if two columns in a row contains two custom values).
I know how I could check the first row thanks to GROUP BY ran on unique index of config__atribute__value table. But what if I want to make another AND to check if some other row also matches different values.
Query abstract representation:
SELECT price
FROM one
LEFT JOIN many
ON one.id = many.fk_one
WHERE (col1 = "some_value" AND col2 = "some_value") AND (col1 = "some_value" AND col2 = "some_value")
GROUP BY one.id
* Both rows have to mach
(ONE) table product_config
id, product_type, inStock, inSale, price
1 "flyers A4" 1 1 800.00
(MANY) table config__atribute__value
id | fk_product_config | fk_product_atribute | fk_product_atribute_value
7 1 "color" "4/0"
8 1 "paper" "120g"
Original query:
The query below works for one row only. But how can I check the next row ?
SELECT price
FROM product_config p
LEFT JOIN config__atribute__value c
ON p.id = c.fk_product_config
WHERE (c.fk_product_atribute = "paper" AND c.fk_product_atribute_value = "120g")
GROUP BY p.id
This will not match anything because it is checking each row for all the values.
SELECT price
FROM product_config p
LEFT JOIN config__atribute__value c
ON p.id = c.fk_product_config
WHERE (c.fk_product_atribute = "paper" AND c.fk_product_atribute_value = "120g") AND (c.fk_product_atribute = "color" AND c.fk_product_atribute_value = "4/0")
GROUP BY p.id
Ideally, if I could use ORDER BY for each row, it would solve my problem, of course this would throw an Error.
SELECT price
FROM product_config p
LEFT JOIN config__atribute__value c
ON p.id = c.fk_product_config
WHERE (c.fk_product_atribute = "paper" AND c.fk_product_atribute_value = "120g")
GROUP BY p.id AND (c.fk_product_atribute = "color" AND c.fk_product_atribute_value = "4/0")
GROUP BY p.id
I am adding this so you can better understand what I am trying to do.