I. database knowledge
1, left join, right join
For example, the record of Table A is as follows:
Id num1 a200501112 a200501123 a200501134 a200501145 a20050115 table B records are as follows:
ID name1 20060324012 20060324023 20060324034 20060324048 2006032408
Statement: Select * from a left join B on A. ID = B. ID;The result is as follows: Id num ID name1 a20050111 1 20060324012 a20050112 2 20060324023 a20050113 3 20060324034 a20050114 4 20060324045 a20050115 null (the number of affected rows is 5) left join is based on the records of table A. A can be seen as the left table, B can be seen as the right table, and left join is based on the left table. In other words, the records in the left table (a) are all expressed, while the right table (B) only displays records that meet the search criteria (in this example:. aid = B. bid ). All records in Table B are null.
SQL statement: Select * from a right join B on A. Aid = B. bid;The results are as follows: Aid anum bid bname1 a20050111 1 20060324012 a20050112 2 20060324023 a20050113 3 20060324034 a20050114 4 2006032404 null 8 2006032408 (affected rows are 5 rows) Result description: right join is based on the records of Table B. A can be seen as the left table, B can be seen as the right table, and right join is based on the right table. In other words, all the records in the right table (B) will be displayed, while the left table (a) will only display records that meet the search criteria (in this example:. aid = B. bid ). All records in Table A are null.
SQL statement: Select * from a inner join B on A. Aid = B. bid;The results are as follows: Aid anum bid bname1 a20050111 1 20060324012 a20050112 2 20060324023 a20050113 3 20060324034 a20050114 4 2006032404 (the number of affected rows is 5 rows) Result description: inner join only displays records in the right table (B) and left table (a) that meet the search criteria (in this example,. aid = B. bid ).
Written review exercise III