sql statement left join, right join, the difference between the inner join

See sql, sql found for a long time did not write very miss ha ha ha ha, a lot of time to learn things are forgotten, when the summary document also how many can not find .....

Closer to home, find a map describing the feeling of quite clear, first map, say that their own understanding.

1.LEFT JOIN (left connection)

select id, name fromg student s left join adddress a on s.id = a.id; (student information will all be detected, no information in the student even address table)

In the left table based , including return all records left table records and the right table join equal field.

2.right JOIN (right connection)

 It is connected with the left similar, comprising a return all records in the right table record and the left table join equal field.

3.INNER JOIN (en)

 

select id, name from student s join address a on s.id = a.id; (If there is no table address corresponding to the student id, not when the query)

 

inner join is actually join, two is one thing. Is equivalent connection , returns only two rows of the table is equal to the coupling field. That is, seek common ground, not associated not displayed.

4.OUTER JOIN (external connection)

Case 1:

 

Is the sum of two outer connection tables A and set B and set . From the perspective of the Cartesian product of the ON clause that pick out the conditions for the establishment of the records from the Cartesian product, and then add the rest of the record left the table, and finally add the remaining records in the right table. In addition MySQL does not support JOIN OUTER , but we can connect the left and right connections to achieve the results do UNION operation.

Case 2:

 

 Recording a condition is not satisfied A and B

 

Guess you like

Origin www.cnblogs.com/syq816/p/12244044.html