when using left jion, the difference between on and where conditions is as follows:
1. On condition is the condition used when generating a temporary table, which returns records from the left table regardless of whether the condition on is true.
2. Where condition is the condition that the temporary table is filtered after the temporal table has been generated. At this point there is no left join meaning (must return the record of the table on the right), the condition is not true all filter out.
Suppose there are two tables:
Table 1 TAB1:
ID size
1 10
2 20
3 30
Table 2 TAB2:
Size Name
Ten AAA
BBB
CCC
Two sql:
1. Select * Form TAB1 LEFT join tab2 on (tab1.size = tab2.size) where tab2.name= ' AAA '
2. Select * Form TAB1 LEFT join tab2 on (tab1.size = tab2.size and Tab2.name= ' AAA ')
The first SQL procedure:
1. Intermediate table
On Condition:
Tab1.size = Tab2.size
Tab1.id tab1.size tab2.size Tab2.name
1 AAA
2 BBB
2 CCC
3 (NULL) (NULL)
2, then the intermediate table filter
Where Condition:
Tab2.name= ' AAA '
Tab1.id tab1.size tab2.size Tab2.name
1 AAA
The second SQL procedure:
1. Intermediate table
On Condition:
Tab1.size = tab2.size and tab2.name= ' AAA '
(The condition is not true also returns the records in the left table)
Tab1.id tab1.size tab2.size Tab2.name
1 AAA
2 (NULL) (NULL)
3 (NULL) (NULL)
In fact, the key reason for the above results is the particularity of the left Join,right Join,full join, regardless of whether the on condition is true will return the records in the left or right table, and full has a set of attributes of left and right. and inner jion does not have this particularity, the condition is placed in and where, the result set returned is the same.
The difference between on and where in the left join of Oracle