Groups | Blog | Home
all groups > sql server programming > july 2004 >

sql server programming : Many to Many / Junction Table Query Help


Chris White
7/26/2004 11:47:53 PM
I need help with a query.
Here are my tables:
[ServiceCategory]
[ServiceCatID] [int] IDENTITY (1, 1) NOT NULL (PRIMARY KEY)
[ServiceCategory] [char] (50) NULL ,

[Services]
[ServiceID] [int] IDENTITY (1, 1) NOT NULL (PRIMARY KEY)
[ServiceCatID] [int] NULL ,
[ServiceName] [char] (100) NULL ,
[ServicePrice] [money] NULL ,

[ServiceDetails]
[ServiceDetailID] [int] IDENTITY (1, 1) NOT NULL (PRIMARY KEY)
[Detail] [char] (50) NULL ,

[ServiceDetailJoin]
[ServiceID] [int] NOT NULL (PRIMARY KEY)
[ServiceDetailID] [int] NOT NULL (PRIMARY KEY)

Services(or Service Plans) and Service Details are Many to Many, different
Services(Service Plans) can have different combinations of Service Details.
ServiceDetailJoin in the junction table to handle these combos.
Not all Services have Service Details, I want a list of All ServiceName and
either Detail or Blank Line

Uri Dimant
7/27/2004 8:58:04 AM
Chris
A General example of many-to-many relationships is
Orders -[Order Details]-Products tables in NorthWind database. At least for
me when I need to do such kind of design.

Now ,let me say we want all products does not matter it has a order or has
not.
SELECT col... FROM Products P LEFT JOIN [Order Details] OD
ON P.ProductId=OD.ProductId


I gave the idea so I hope you can solve the problem




[quoted text, click to view]

AddThis Social Bookmark Button