Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
JOIN with a condition
Message
 
To
14/09/2006 09:33:42
Mike Cole
Yellow Lab Technologies
Stanley, Iowa, United States
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Miscellaneous
Thread ID:
01153646
Message ID:
01153653
Views:
11
>What I am trying to do is create a generic ContactInfo table that has a field of ContactType to tell what type on contact it is, and then link to that table from a query where I only want a specific ContactType (in this case, 1). I thought the following join statement would work, but it seems to ignore that part of the statement.
>
>
>FROM         ContactType RIGHT OUTER JOIN
>                      ContactInfo ON ContactType.ContactTypeID = ContactInfo.ContactType AND ContactInfo.ContactType = 1 RIGHT OUTER JOIN
>                      CustAddr ON ContactInfo.CustNum = CustAddr.CustNum
>
>
>Anybody know what I am doing wrong? Thanks!

You right joined CustAddr to ContactInfo, that means you want all records from CustAddr and mathching records ContactInfo.
FROM         ContactType
RIGHT JOIN ContactInfo ON ContactType.ContactTypeID = ContactInfo.ContactType AND ContactInfo.ContactType = 1
RIGHT JOIN CustAddr    ON ContactInfo.CustNum       = CustAddr.CustNum
I would do something different (becuase I didn't see any reasons for RIGHT JOIN)
FROM       ContactInfo  
LEFT JOIN ContactType ON ContactType.ContactTypeID = ContactInfo.ContactType
LEFT JOIN CustAddr    ON ContactInfo.CustNum       = CustAddr.CustNum
WHERE ContactInfo.ContactType = 1
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Previous
Reply
Map
View

Click here to load this message in the networking platform