The difference between left join (left association), right join (right-associative), inner join (autocorrelation) associated with the use of the left |||

Illustrated by a picture of the difference between the three:

Here Insert Picture Description

to sum up:

left join (left coupling) Returns includes all records in the left table and the right table record associated fields are equal

right join (the right coupling) includes all the records and returns the left table in the right table record associated field equal

inner join (equivalent connections) returns only two rows in the table equal to the associated field
for example as follows:

Recorded as follows in Table A:

Aarea aID
1 Beijing
2 Shanghai
3 Guangzhou
4 Shenzhen
5 Hong Kong
Table B recorded as follows:
bID bname
1 Wang
2 Zhang
3 Li
4 Chen
8 small yellow


1.left join
sql语句如下:
select * from A
left join B
on A.aID = B.bID

The results are as follows:
aID Aarea bID bname
1 1 Wang Beijing
2 Shanghai Zhang 2
3 3 Li Guangzhou
4 Shenzhen Chen 4
5 Hong Kong NULL NULL

(Effect of the number of rows 5 rows)
examples:

A record left join is based on a table on the left, that is, the left table (A) records will all be displayed, while the right table (B) will only show records that match the search criteria.

Lack of local B table records are NULL.

The Join 2.Right
SQL statement is as follows:
the SELECT * from A
right the Join B
ON A.aID = B.bID
results are as follows:
aID Aarea bID bname
1 1 Wang Beijing
2 Shanghai Zhang 2
3 Guangzhou Li 3
4 4 Chen Shenzhen
NULL NULL 8 small yellow

(Affecting the number of rows 5 rows)
examples:
right is recorded on the right side of the Join Table B basis, that is, the right table (B) of the record will show all out, and left the table (A) only display records that meet the search criteria. And the result left join just the opposite, this is the right table (B) based on the lack of local A table filled with NULL.

3.inner join
sql语句如下:
select * from A
innerjoin B
on A.aID = B.bID

The results are as follows:
aID Aarea bID bname
1 1 Wang Beijing
2 Shanghai Zhang 2
3 Guangzhou Li 3
4 4 Chen Shenzhen

(Affecting the number of lines to 4 lines)

Examples:
here only shows records A.aID = B.bID instructions not to Who inner join basis, it shows only the matching records.

(Author: ChenJZ_8 Source: CSDN Original: https://blog.csdn.net/ChenJZ_8/article/details/80451683 Copyright: This article is a blogger original article, reproduced, please attach Bowen link!)

Left usage associated
SELECT aX, bX a left from the Join B ON a.id = b.id and (WHERE) = B.class. 1
and does not work on a table, for from B
WHERE for a, b are functional

Examples: select b.inp_no, a.discharge_date_time (with later select these circumstances, can be added from time to increase)
from pat_visit A
left the Join pat_master_index B = ON a.patient_id b.patient_id
WHERE a.discharge_date_time> = TO_DATE ( '20,190,601', ' YYYYMMDD ')
and a.discharge_date_time <= TO_DATE (' 20,190,605 ',' YYYYMMDD ')
and a.visit_id> 0
(wHERE conditions by addition of the back)

Guess you like

Origin blog.csdn.net/weixin_44447804/article/details/91411913