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,970 of 19,505   
   Lennart Jonsson to Roger   
   Re: Joining from 2 different tables   
   23 Oct 10 06:56:30   
   
   From: erik.lennart.jonsson@gmail.com   
      
   On 2010-10-22 15:59, Roger wrote:   
   [...]   
   >   
   > 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)   
   >   
   > but then you will need two sets of columns for employee and customer   
   > i.e. select c.firstname, c.lastname, e.firstname, e.lastname   
   >   
      
   You could output only one of them as in:   
      
   case when c.firstname is not null then c.firstname else e.firstname end   
   as firstname, ...   
      
   or   
      
   coalesce(c.firstname , e.firstname) as firstname, ...   
      
   but a union is the most natural choice here   
      
      
   /Lennart   
      
   --- 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