Forum Moderators: open
Product:
product_id¦name
1 ¦My TV
2 ¦HD TV
3 ¦Plasma TV
Product_Choices:
choice_id¦product_id¦choice_value
1 ¦1 ¦ Sony
2 ¦1 ¦ Black
3 ¦1 ¦ 32
4 ¦2 ¦ Sony
5 ¦2 ¦ Silver
6 ¦2 ¦ 32
7 ¦3 ¦ Sony
8 ¦3 ¦ Silver
9 ¦3 ¦ 42
Now if a user wants to search all Sony products, my query looks like
SELECT product_id
FROM PRODUCT_CHOICES
WHERE value='Sony'
But what if a user wants to search for all products with value Sony and 32
This query wont work:
SELECT product_id
FROM PRODUCT_CHOICES
WHERE value='Sony' and value='32'
SELECT product_id
FROM PRODUCT_CHOICES pc1,
PRODUCT_CHOICES pc2
WHERE pc1.value='Sony'
AND pc2.value='32'
and pc1.PRODUCT_ID=pc2.PRODUCT_ID
Is there a better way to do this. I'm beginning to doubt my database structure. How else can I store and retrieve a product and its attributes. The design looks good if you want to get all the attributes of a product based on the product ID, but if you want to go in the reverse direction, ie to get all products that have certain attributes, it seems to get difficult.
Appreciate your help.
Thanks