asp.net - How to select product with multiple categories -


according title of question have structure access database this:

category

categoryid   categoryname 1            1 2            2 3            3 

product table:

productid    productname    categories 1            1            1,2,3 2            2            3 3            3          1,2 

when have categoryid 1 dont know way select product have multiple categorise. because when use in operator,i getting error..

select * product categories in (categodyid) because cannot compare collection 1 value. 

i'm stuck @ here! please me! thanks.

first of all, tables not normalized. @ categories column in product table. each cell should have 1 value. allowing multiple values, risk various problems including update/insert anomalies , seeing now. make difficult selects , other operations. instead, think normalizing tables example:

category

categoryid   categoryname 1            1 2            2 3            3 

product

prodductid   productname 4            prod1 5            prod2 6            prod 3 

category_prod

categoryid   productid 1            3 1            4 2            3 

the third table acts way remedy many many pattern. if have questions on how or how use it, let me know


Comments

Popular posts from this blog

ios - iPhone/iPad different view orientations in different views , and apple approval process -

monitor web browser programmatically in Android? -

c# - Using multiple datasets in RDLC -