initforthemoney
Programmer
Hi
I am really stuck on this one. Just cant get my head around it. Maybe some one can help.
I have the following tables:
Table Name: Product
ID PK
Name
Table Name: Option
ID PK
Name
Table Name: OptionType
ID PK
OptionID FK
ProductName
Table Name: ProductOptionType
ID PK
ProductID FK
OptionID FK
OptionTypeID FK
Some example data for the ProductOptionType table looks like this:
ID ProductID OptionID OptionTypeID
1 1 1 1
2 1 2 3
3 2 1 1
I am trying to get all the products that have OptionTypeID = 1 and OptionTypeID = 3. In the example the result set would only bring back product ID 1 becuase OptionTypeID's 1 and 3 have been assigned. Product ID 2 will not come back because it only has OptionTypeID 1 assigned. I hope this is clear
Would you say this is a good DB design to add flexibility to a product? A product can be assigned many options like (Size, Colour, etc). An option can have many types (Colour can have Red, Green, Blue etc). An admin screen would assign each product with its specific options and option types which are stored in the ProductOptionType table.
The above query will be used in an advanced search form. The user could select from drop down lists they want all products that are Colour: Red and Size: Large.
Maybe my db design could be improved to make the query easier?
Thanks
I am really stuck on this one. Just cant get my head around it. Maybe some one can help.
I have the following tables:
Table Name: Product
ID PK
Name
Table Name: Option
ID PK
Name
Table Name: OptionType
ID PK
OptionID FK
ProductName
Table Name: ProductOptionType
ID PK
ProductID FK
OptionID FK
OptionTypeID FK
Some example data for the ProductOptionType table looks like this:
ID ProductID OptionID OptionTypeID
1 1 1 1
2 1 2 3
3 2 1 1
I am trying to get all the products that have OptionTypeID = 1 and OptionTypeID = 3. In the example the result set would only bring back product ID 1 becuase OptionTypeID's 1 and 3 have been assigned. Product ID 2 will not come back because it only has OptionTypeID 1 assigned. I hope this is clear
Would you say this is a good DB design to add flexibility to a product? A product can be assigned many options like (Size, Colour, etc). An option can have many types (Colour can have Red, Green, Blue etc). An admin screen would assign each product with its specific options and option types which are stored in the ProductOptionType table.
The above query will be used in an advanced search form. The user could select from drop down lists they want all products that are Colour: Red and Size: Large.
Maybe my db design could be improved to make the query easier?
Thanks