Home > database >  A great god, please explain why the results of the two SQL is not the same
A great god, please explain why the results of the two SQL is not the same

Time:10-21

CodePudding user response:

Constraints position is different, the result is also different

CodePudding user response:

Inside the building Lord first introduce simple connection, connection on the left, the right connection

CodePudding user response:

The first is equal to the inside connection, the second is the outer join

CodePudding user response:

On the back is a cartesian product filter two links table form the table in the middle of the constraint condition, the where is on the table in the middle of the constraint condition, connection is recommended on only for operation, where only filter the table in the middle of the record,

CodePudding user response:

So the original poster +. If you use to say outside connected with this question

CodePudding user response:

The two values equivalent
 select * 
The from tab1 t1
Left the join tab2 t2 on t1. Col1=t2. Col2
Where t2 col2!=3
;
Select * from (
Select *
The from tab1 t1
Left the join tab2 t2 on t1, col1=t2. Col2) t1
Where a t1 col2!=3
;

The two are equivalent
 select * 
The from tab1 t1
Left the join tab2 t2 on t1. Col1=t2. Col2
And t2 col2!=3
;

Select *
The from tab1 t1,
Tab2 t2
Where a t1. Col1=t2. Col2 (+)
And t2. Col2 (+)!=3
;

CodePudding user response:

1, the SELECT * FROM A LEFT JOIN B ON condition 1 AND condition 2
2, the SELECT * FROM A LEFT JOIN ON condition 1 WHERE 2 B
First, the condition 2 whether or not, will not affect A table data display,
Second, condition 2 if not satisfied, can affect A table data shows,
  • Related