Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
initforthemoney
Starting Member
2 Posts |
Posted - 2005-11-07 : 16:13:18
|
| HiI 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: ProductID PKNameTable Name: OptionID PKNameTable Name: OptionTypeID PKOptionID FKProductNameTable Name: ProductOptionTypeID PKProductID FKOptionID FKOptionTypeID FKSome example data for the ProductOptionType table looks like this:ID ProductID OptionID OptionTypeID1 1 1 12 1 2 33 2 1 1I 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 clearWould 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 would select from drop down lists (The OptionTypeID's) for example Colour: Red and Size: Large. Only products matching both critera are returned.Maybe my db design could be improved to make the query easier?Thanks |
|
|
initforthemoney
Starting Member
2 Posts |
Posted - 2005-11-07 : 19:50:40
|
| Hi As a newcomer to this forum I was just having a quick browse of some previous posts and luckily found this thread:http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=55803 It solves my problem perfectly :-)I tried this out and it worked:select ProductIDfrom ProductOptionTypewhere OptionTypeID in (1, 4)group by ProductIDhaving count(OptionTypeID) = 2I could really do with a good book on SQL. My knowledge is not quite as good as I would like it to be. Any recommendations? Cool forumThanks |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2005-11-07 : 19:52:32
|
| http://www.sqlteam.com/store.aspI recommend Ken Henderson's books.Tara Kizer |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
|
|
|
|