sql server - SQL join multiple columns into different rows -


i have 2 tables name combine , product , combine has multiple products inside , combine has strictly 3 products have 2 tables strutred below:

combine | id | name   | image                   | item1 | item2 | item3           1  | exmpl  | www.exmpl.com/exmp.jpg  | 3     | 2     | 16   product | id | name          | image                           | stock              2  | productexmpl  | www.product.com/product2.jpg    |  3               3  | productexmpl2 | www.product.com/product3.jpg    |  7            16 | productexmpl3 | www.product.com/product16.jpg   |  3  

what want search combine id select * combine id = '' , combine products in different rows , i've tried join tables select * combine c join product p on c.item1 = p.id , c.item2 = p.id , c.item3 = p.id joins information horizontally want information vertically means in different rows below

  id | name          | image                           | stock      2  | productexmpl  | www.product.com/product2.jpg    |  3       3  | productexmpl2 | www.product.com/product3.jpg    |  7    16 | productexmpl3 | www.product.com/product16.jpg   |  3  

i dont know if structre wrong design appreciated

thank you

you can try query:

select p.id, p.name, p.image, p.stock combine c inner join product p on (c.item1=p.id or c.item2=p.id or c.item3=p.id) id = ### 

Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -