I have created a database containing specifications of products, product names, shops. The setup of the specification table (product_specs_koppel) is the following:
pid | sid | value
1 | 1 | Y
2 | 1 | N
1 | 2 | 30
2 | 2 | 30
Where pid = product ID, sid = specification ID and value is the value of that specification. So far no problem, I store the names of the specification is a different table which can be linked on sid.
The problem comes with the selection out of the database. As an example, I want to select all pid's, with the following condition:
- sid 1 -> Y
- sid 2 -> 30
I can create two subqueriesy in the main query, but this would not be a scalable solution:
SELECT
p.naam, k.pid, waarde
FROM
product_producten p
INNER JOIN product_specs_koppel k ON (k.pid = p.id)
WHERE
k.pid IN
(Select k1.pid from product_specs_koppel k1 where k1.sid = '1' AND
k1.waarde = 'Y') AND
k.pid IN
(select k2.pid from product_specs_koppel k2 where k2.sid = '2' AND
k2.waarde = '30')
Any suggestions if there is a better way to setup the database or change/update my query to a more scalable solution?