Written review exercise III

Source: Internet
Author: User
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

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.