[thelist] ASP.NET: UNION query not returning expected results

Phil Turmel pturmel-webdev at turmel.org
Thu Sep 27 20:47:08 CDT 2007


r937 wrote:
> SELECT O.id               AS OfficeID
>      , O.number           AS Office 
>   FROM dbo.Employees as E
> INNER
>   JOIN dbo.Offices as O
>     ON O.id = E.OfficeID
>  WHERE E.id = 57 
> UNION ALL
> SELECT O.id  
>      , O.number  
>   FROM dbo.Offices as O
> LEFT OUTER
>   JOIN dbo.Employees as E
>     ON E.OfficeID = O.id
>  WHERE E.OfficeID IS NULL 
> 
> 
> any questions, please just ask
> 
> ;o)
> 
Hi Joel, Rudy:

Sorry for jumping in late, but why have a union at all?

SELECT O.id
     , O.number
  FROM dbo.Offices as O
LEFT OUTER
  JOIN dbo.Employees as E
    ON E.OfficeID = O.id
 WHERE E.OfficeID IS NULL OR E.id = 57

                          ^^^^^^^^^^^^

HTH,

Phil



More information about the thelist mailing list