Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > Microsoft SQL Server > Outer joins in ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 3 Topic 11101 of 11517
Post > Topic >>

Outer joins in MS SQL 2005: why is it this way? better yet, any

by fullofquestions <fullofquestions@[EMAIL PROTECTED] > Jun 2, 2008 at 01:50 PM

I am writing a simple query involving three tables (see below). I
would like to display all customers along with their industry
regardless of whether or not the customer has been assigned an
industry.

Table 'Customers' has 426 unique rows

Table 'CustomerAttribute' is linked with/to 'Customers' where
Customers.custid = CustomerAttribute.custid

Table 'Industry' is linked with/to 'CustomerAttribute' where
CustomerAttribute.industryid = Industry.industryid. Furthermore,
CustomerAttribute.industryid is defined where
CustomerAttribute.attributeid = 6

The following query returns 214 row, ie. not what I need:
select cust.code, cust.name, I.code, I.Name
from customer cust left join customerAttribute CA on Cust.custid =
CA.custid
left join Industry I on CA.industryID = I.industryID
where CA.attributeid = 6
Order by cust.name

The following two queries returns 426 row, ie what I want. Why is
this? Better yet, does anyone have a good resource on these subtleties
with MS SQL?(as far as I am concerned the queries below make sense but
I have never had to use this notation)
select cust.code, cust.name, I.code, I.Name
from customer cust left join (select * from customerAttribute where
attributeid=6) CA on Cust.custid = CA.custid
left join Industry I on CA.industryID = I.industryID
Order by cust.name

select cust.code, cust.name, I.code, I.Name
from customer cust left join customerAttribute CA on (Cust.custid =
CA.custid AND CA.attributeid = 6)
left join Industry I on CA.industryID = I.industryID
Order by cust.name
 




 3 Posts in Topic:
Outer joins in MS SQL 2005: why is it this way? better yet, any
fullofquestions <fullo  2008-06-02 13:50:16 
Re: Outer joins in MS SQL 2005: why is it this way? better yet,
"Plamen Ratchev"  2008-06-02 17:02:32 
Re: Outer joins in MS SQL 2005: why is it this way? better yet,
--CELKO-- <jcelko212@[  2008-06-02 16:10:15 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed Dec 3 1:19:59 CST 2008.