home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.databases.ms-sqlserver      Notorious Rube Goldberg contraption      19,505 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 17,972 of 19,505   
   tshad to Roger   
   Re: Joining from 2 different tables   
   24 Oct 10 19:37:02   
   
   From: tfs@dslextreme.com   
      
   "Roger"  wrote in message   
   news:4_udnZzfXe6Ekl7RnZ2dnUVZ7qGdnZ2d@bt.com...   
   > "tshad"  wrote in message   
   > news:Zwowo.4911$jw4.3982@newsfe21.iad...   
   >>   
   >>>   
   >>> You could use a left join and exclude the empty rows in the where   
   >>> clause...   
   >>>   
   >>> left JOIN EmployeeAnswerMap on EAM.AnswerID = A.AnswerID   
   >>> left JOIN CustomerAnswerMap on CAM.AnswerID = A.AnswerID   
   >>> where not (EAM.AnswerID is null and CAM.AnswerID is null)   
   >>>   
   >>   
   >> That was what I tried.   
   >>   
   >> But I don't seem to get all of them.   
   >>   
   >> If I do a UNION, I get 11 records.  If I do each separately, I get 6 for   
   >> employees and 5 for customers.   
   >>   
   >> But if I do the left Joins, I am only getting 7 records.   
   >>   
   >> Can't figure out why that is not getting the other 4.   
   >   
   > Hi Tom,   
   >   
   > That's probably correct.   
   >   
   > If some questions are answered by both customer and employee, you will   
   > only get one row for each answer   
   >   
      
   You're right.  Which is why I sent a schema with various queries that show   
   those issues.   
      
   Maybe UNION is the best way to handle it but I just wanted to see if there   
   was a better way to handle it not using UNIONs.  As I mentioned in the other   
   post, the one without the UNION performs better but I don't get the correct   
   response.   
      
   Thanks,   
      
   Tom   
      
   > e.g. 10 questions   
   > 4 answered by both   
   > 1 answered by customer only   
   > 2 answered by employee only   
   >   
   > left join = 7 rows   
   > union = 11 rows   
   >   
   > --   
   > Roger   
   >   
   >   
   >   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca