Re: Outer Join not working
From: Hugo Kornelis (hugo_at_pe_NO_rFact.in_SPAM_fo)
Date: 02/25/05
- Next message: Hugo Kornelis: "Re: How To Catch Output from SP / Function"
- Previous message: Klaus Aschenbrenner: "Re: DataSet Performance"
- In reply to: tshad: "Re: Outer Join not working"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 25 Feb 2005 13:33:07 +0100
On Thu, 24 Feb 2005 23:49:52 -0800, tshad wrote:
(snip)
>I am still not sure why I had to move the JobID test into the "on" clause,
>but it worked. I will have to study it more to understand it.
Hi Tom,
That's because of the order in which a SELECT statement is evaluated.
The order of evaluation whould, in theory (most DBMS's will reshuffle to
optimize, as long as it doesn't change the end result), be as follows:
1. Evaluate FROM clause. Make a temporary result set that holds all
columns from all tables in the FROM clause, with all the rows that
satisfy the ON conditions.
Rows that don't match the ON condition are not included if it's an INNER
JOIN; for OUTER JOINS, the row from the outer table will be retained
with NULL values substituted for the columns from the inner table.
2. Evaluate WHERE clause. Check each row in the temporary result set
from the previous step against the WHERE condition. The row is retained
only if the WHERE condition evaluates to TRUE. If it evaluates to FALSE
or UNKNOWN, the row is removed from the result set.
3. After this, the GROUP BY, HAVING, SELECT and ORDER BY are processed
(in that order) - but these are not relevant for your question.
In your original question, you had a WHERE clause
where JobID = 3720
where the JobID column is from the inner table of an outer join. For all
rows retained because of the outer join, JobID is NULL. By definition,
the expression NULL = 3270 evaluates to FALSE. Therefor, all rows
retained by the outer join are subsequently removed by the where clause,
effectively changing your query to an inner join.
Best, Hugo
-- (Remove _NO_ and _SPAM_ to get my e-mail address)
- Next message: Hugo Kornelis: "Re: How To Catch Output from SP / Function"
- Previous message: Klaus Aschenbrenner: "Re: DataSet Performance"
- In reply to: tshad: "Re: Outer Join not working"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|