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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Retriving datas from multiple table

Author  Topic 

bplvid
Starting Member

45 Posts

Posted - 2012-05-09 : 12:20:37
I've one parent table with 7 child tables.I've a relaionship table holding parenttableid and bridgetableid.One item from parent table can be related to multiple data's in my relationship table.One(parent item) - many(bridgetableid) relationship.for eg.

parent table


Itemid
Itemdesc.

product table

Productid
productname


relationshiptable

Itemid Productid

001 230
001 678
001 567
001 874

002 567
002 678


Now what I need is I need to get all the productname listed under a particular user and at the same time show the itemid that are related to that productid.something like this

productname productid itemid

product a 567 002
product b 678 002
product c 230 null
product d 874 null

I'm doing this for the user to see all the products available and letting the user know by productname checkcheckbox based on dbvalue that relate to a particular item.

Hope I was clear with my question.What kind of approach should I follow.Should I have 2 different select statements for selecting all the productname and another one for retriving productname based on itemid reference.Any good suggestion plz.Tried a lot and finally here for expert advice.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-05-09 : 15:51:16
you can use like below

SELECT p.productname,
p.productid,
r.itemid
FROM product p
LEFT JOIN relationshiptable r
on r.productid = p.productid


didnt understand how you will link it to user though as i cant see any user related information in product or relationship tables

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -