Sunday, 15 February 2015

sql - How to fetch data from tables where there is one to many relationship? -



sql - How to fetch data from tables where there is one to many relationship? -

i have created 3 tables product, brands , productbrands in ms sql server these tables contains info following

products (pid - pname)

1 - mobiles 2 - t.v 3 - a.c

brands (bid - bname)

1 - samsung 2 - sony 3 - l.g

productsbrands (pbid - pid - bid)

1 - 1 - 1 2 - 1 - 2 3 - 1 - 3 4 - 2 - 1 5 - 2 - 3

...

...

now have fetch tables next feilds

product id pname bid bname

basically have fetch brands assigned products

please help me!!! new this

select p.pid , p.pname, b.bid, b.bname products p bring together productsbrands pb on pb.pid = p.pid bring together brands b on b.bid = pb.bid

see, whether looking for.

sql sql-server sql-server-2008

No comments:

Post a Comment