Borrowed a bo friend: http://blog.csdn.net/tomholmes7/article/details/5786166
The table structure is established as follows:
Create Table A (A1 int, a2 varchar (10));
CREATE TABLE B (b1 int, B2 varchar (10));
CREATE TABLE C (c1 int, C2 varchar (10));
Insert into a values (1, ' haha ');
Insert into a values (2, ' ssss ');
Insert into a values (4, ' tttt ');
Insert into B values (1, ' CCCC ');
INSERT into C values (2, ' xxxx ');
Perform the following two left joins:
SELECT * from a
Left JOIN B on A.A1=B.B1
Left join C on A.A1=C.C1;
SELECT * from a
Left JOIN B on A.A1=B.B1
Left join C on B.B1=C.C1;
The result is actually different:
The former is:
The latter is:
Personal Understanding:
The left join is based on the records of Table A, a can be regarded as the right table, and B can be regarded as left table. In other words, the records of the left table (A) will all be represented, and the right table (B) will only display records that match the search criteria (in the example: A.aid = b.bid). The low-record of table B is null.
When the left join is C, it is the temporary table generated with a to join B as the main table and then go to the "join" C table, which I understand.
A LEFT join B on A.A1=B.B1 left join C on a.a1=c.c1 = tied up, basically no problem
Left JOIN multi-table operation