Left join, join, right join difference, leftjoinLeft join returns records that include all records in the left table and join fields in the right table.Right join returns records that include all records in the right table and the
[/Color] [color = Green] Table A records as follows:Aid anum1 A112 A223 A334 A445 A55
Table B records the following:Bid bname1 B112 B223 B334 b448 b88
The SQL statements for creating these two tables are as follows:Create TableAid int (1) auto_increment primary key,Anum char (20))Create Table B (Bid int (1) not null auto_increment primary key,Bname char (20))
INSERT INTOValues (1, 'a11 ');Commit;.....
Insert into BValues (1, 'b11 ');Commit;.....
1. Left join
The following is an exampleTable A records the following:Aid anum1 a200501112 a200501123 a200501134 a200501145 a20050115
Table B records the following:Bid bname1 20060324012 20060324023 20060324034 20060324048 2006032408
The SQL statements for creating these two tables are as follows:Create TableAid int (1) auto_increment primary key,Anum char (20))Create Table B (Bid int (1) not null auto_increment primary key,Bname char (20))
INSERT INTOValues (1, 'a20050111'), (2, 'a20050112'), (3, 'a20050113
EFT Join (left JOIN) returns records that include all records in the left table and the equivalent of the junction fields in the right tableRight join returns records that include all records in the right table and the junction fields in the left tableINNER JOIN (equivalent join
Tags: operations same field record group type search using left join firstLeft join returns records that include all the records in the left table and the equivalent of the junction fields in the right tableRight join returns records that include all records in the right table and the junction fields in the left tableINNER JO
Label:Left join returns records that include all the records in the left table and the equivalent of the junction fields in the right tableRight join returns records that include all records in the right table and the junction fields in the left tableINNER JOIN (equivalent join) returns only rows that have the same
Left join returns records that include all records in the left table and join fields in the right table.Right join returns records that include all records in the right table and the joined fields in the left table.Inner join (equivalent join) returns only rows with equal
Table A records the following:
Aid anum1 a200501112 a200501123 a200501134 a200501145 a20050115
Table B records the following:Bid bname1 20060324012 20060324023 20060324034 20060324048 2006032408The experiment is as follows:1. Left joinThe SQL statement is as follows:
Select
*
From
A
Left
Join
B
On
A. Aid
=
B. Bid
The result is as follows: Aid anum bid bname1 a20050111 1 20060324012 a20050112 2 20060324023 a200501
Left join returns records that include all the records in the left table and the equivalent of the junction fields in the right tableRight join returns records that include all records in the right table and the junction fields in the left tableINNER JOIN (equivalent join) returns only rows that have the same
Table connection methods and usage scenarios
NESTED LOOP
For a small subset of connected data, nested loop connection is a good choice. The nested loop is used to scan a table. Every time a record is read, it is searched in another table based on the index. Without an index, it is generally not nested loops.Generally, in the nested loop, the result set of the driver table meeting the condition is not large, and the connected fields of the driver table must be indexed, so that nstedloop is used.
Here is an example analysis
Table A records as follows:
AID Anum
1 a20050111
2 a20050112
3 a20050113
4 a20050114
5 a20050115
Table B is recorded as follows:
BID bname
1 2006032401
2 2006032402
3 2006032403
4 2006032404
8 2006032408
Create the two tables SQL statements as follows:
CREATE TABLE A
AID Int (1) auto_increment PRIMARY KEY,
Anum Char (20)
)
CREATE TABLE B (
BID Int (1) not NULL auto_increment PRIMARY KEY,
Bname Char (20)
)
INSERT into a
VALUES (1, ' a20050111 '), (2, ' a20050112 '),
Tags: case ble add left join Karl Baidu Oss intersection useUsing the Join table, the defect is inner join, the left join used in development and the right join belong to outer join,outer join
Left join returns records that include all the records in the left table and the equivalent of the junction fields in the right tableRight join returns records that include all records in the right table and the junction fields in the left tableINNER JOIN (equivalent join) returns only rows that have the same
Label:Left join returns records that include all the records in the left table and the equivalent of the junction fields in the right tableRight join returns records that include all records in the right table and the junction fields in the left tableINNER JOIN (equivalent join) returns only rows that have the same
Tags: relationship body syntax base padding Local Data type example conditionsLeft join returns records that include all the records in the left table and the equivalent of the junction fields in the right tableRight join returns records that include all records in the right table and the junction fields in the left tableINNER JOIN (equivalent
Left join returns records that include all the records in the left table and the equivalent of the junction fields in the right tableRight join returns records that include all records in the right table and the junction fields in the left tableINNER JOIN (equivalent join) returns only rows that have the same
Table A is as follows:
AID
Anum
1
a20110111
2
a20110112
3
a20110113
4
a20110114
5
a20110115
Table B is as follows:
BID
Bname
1
bName0111
2
bName0112
3
bName0113
4
bName0114
8
bName0118
One, left join ... on
MySQL statement:
SELE
Tags: using SP data on BS EF SQL nbsp CLeft join returns records that include all the records in the left table and the equivalent of the junction fields in the right tableRight join returns records that include all records in the right table and the junction fields in the left tableINNER JOIN (equivalent join) returns
When a database returns records by connecting two or more tables, an intermediate temporary table is generated, and the temporary table is returned to the user.For example, the following two tables:A (aid int, Aname char (10))B (aid int, Aname char (10))Corresponding data: EXECUTE statement: SELECT * from a left JOIN B on aid=bid My understanding is that a left connection B, first take a record in a, according to the conditions in the on to
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.