When you impose a condition (WHERE clause) on a join you essentially make that join an inner join.Consider the following code:DECLARE @TableA TABLE (ID int)DECLARE @TableB TABLE (ID int)INSERT @TableASELECT 1 UNION ALLSELECT 2 UNION ALLSELECT 3 UNION ALLSELECT 4 UNION ALLSELECT 5 UNION ALLSELECT 6INSERT @TableBSELECT 1 UNION ALLSELECT 2 UNION ALLSELECT 6SELECT *FROM @TableA aINNER JOIN @TableB bON a.ID = b.IDSELECT *FROM @TableA aLEFT OUTER JOIN @TableB bON a.ID = b.IDSELECT *FROM @TableA aLEFT OUTER JOIN @TableB bON a.ID = b.IDWHERE a.ID = b.ID
Notice how the inner join and the left outer join with a where clause return the same results.I'm not 100% sure how to solve your problem from what you have described, but you might try moving the "conditions" out of your WHERE clause and put them on the join. for example:select somedata, somedata, somedata, somedataFrom kpi..temptablel lleft outer join @temps s on l.x = s.x AND l.y = s.yleft outer join @tempf f on l.x = f.x AND l.y = f.yleft outer join kpi..temptablee e on l.x = e.x AND l.y = e.yleft outer join @tempn n on l.x = n.x AND l.y = n.y
Or perhaps, you need to do some GROUPing or a DISTINCT to get what you are after. If you have some sample data and expected results, I'm sure we can help you out.-Ryan