You are on page 1of 1

74 Chapter 3: Selecting

Heres what the equivalent SELECT looks like now:


SELECT t1.key_1,
t1.non_key_1,
t2.key_1,
t2.key_2,
t3.key_1,
t3.non_key_1,
t1.key_1 * 100 AS a,
t3.key_1 * 1000 AS b
FROM ( t1 LEFT OUTER JOIN t2 ON t1.key_1 = t2.key_1 )
CROSS JOIN t3;
Here is what the candidate result set looks like at this point:
t1. t1. t2. t2. t3. t3.
key_1 non_key_1 key_1 key_2 key_1 non_key_1 a b
===== ========= ===== ===== ===== ========= === ====
A 1 1 NULL NULL 3 333 100 3000
B 1 1 NULL NULL 4 333 100 4000
C 1 1 NULL NULL 5 0 100 5000
D 1 1 NULL NULL 6 333 100 6000

E 2 2 2 21 3 333 200 3000


F 2 2 2 22 3 333 200 3000
G 2 2 2 23 3 333 200 3000

H 2 2 2 21 4 333 200 4000


I 2 2 2 22 4 333 200 4000
J 2 2 2 23 4 333 200 4000

K 2 2 2 21 5 0 200 5000
L 2 2 2 22 5 0 200 5000
M 2 2 2 23 5 0 200 5000

N 2 2 2 21 6 333 200 6000


O 2 2 2 22 6 333 200 6000
P 2 2 2 23 6 333 200 6000

Note: The rows are shown in a sorted order so its easier to see whats going
on. In reality, no particular order can be assumed until the ORDER BY clause is
applied, and that doesnt happen until much later.

Step 3: The WHERE clause is applied to eliminate rows.


The WHERE clause may refer to both virtual columns and select list items,
but not to aggregate function calls or NUMBER(*) calls. Heres what the equiv-
alent SELECT looks like now:
SELECT t1.key_1,
t1.non_key_1,
t2.key_1,
t2.key_2,
t3.key_1,
t3.non_key_1,
t1.key_1 * 100 AS a,
t3.key_1 * 1000 AS b
FROM ( t1 LEFT OUTER JOIN t2 ON t1.key_1 = t2.key_1 )
CROSS JOIN t3
WHERE b <= 5000
AND t3.non_key_1 = 333;

You might also like