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

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -