Table A records as follows:
aID aNum
1 a11
2 a22
3 a33
4 a44
5 a55
Table B records as follows:
bID bName
1 b11
2 b22
3 b33
4 b44
8 b88
The SQL statements for creating these two tables are 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, 'a11' );
commit;
.....
INSERT INTO b
VALUES ( 1, 'b11' );
commit;
.....
1.left join (left join)
sql语句如下:
SELECT * FROM a
LEFT JOIN b
ON a.aID =b.bID
The results are as follows:
aID aNum bID bName
1 a11 1 b11
2 a22 2 b22
3 a33 3 b33
4 a44 4 b44
5 a55 NULL NULL
(the number of rows affected is 5 rows)
Result description:
left join is based on the records of table A, A can