Natural connection, external connection, internal connection, the difference between left and right connections and introduction

Source: Internet
Author: User

Not to go out of the world do not know that their database is so garbage, even the difficult SQL statement will not write, sad urge.

Suppose there is a A, a, two table. Table A is recorded as follows: AID Anum1a200501112a200501123a200501134a200501145a20050115 table B is recorded as follows: BID bname1     2006032401  2     2006032402  3     2006032403  4     2006032404  8     2006032408   --------------------------------------------  1. Left JoinThe SQL statements are as follows:Select *  fromA Left JoinB onA.aid=b.bid results are as follows: AID anum BID bname1a200501111     2006032401  2a200501122     2006032402  3a200501133     2006032403  4a200501144     2006032404  5a20050115NULL     NULL(the number of rows affected is5line) result Description: LeftJoin is based on the records of a table, a can be seen as the left table, B can be regarded as the right table, Leftjoin is based on left table. In other words, the records of the left table (A) will all be represented, and the right table (B) will only display records that match the search criteria (in the example: A.aid=b.bid). The low-record of table B is null. --------------------------------------------  2. Right JoinThe SQL statements are as follows:Select *  fromA Right JoinB onA.aid=b.bid results are as follows: AID anum BID bname1a200501111     2006032401  2a200501122     2006032402  3a200501133     2006032403  4a200501144     2006032404  NULL     NULL     8     2006032408(the number of rows affected is5result Description: Look closely, you will find that the result of the left join is exactly the opposite, this time is based on the right table (B), a table is not enough to fill with null. --------------------------------------------  3.Inner JoinThe SQL statements are as follows:Select *  fromA innerjoin B onA.aid=b.bid results are as follows: AID anum BID bname1a200501111     2006032401  2a200501122     2006032402  3a200501133     2006032403  4a200501144     2006032404The results show: Obviously, this shows only the A.aid=B.bid Records. This shows that inner join is not based on who, it only shows records that match the criteria. --------------------------------------------  PS: LeftThe join operation is used for any fromclause to combine records from the source table. Use Left JOINoperation to create a left outer join.    The left outer join will contain all of the records from the first (left) two tables, even if there are no records of the corresponding values in the second (right) table. Syntax: fromTable1 Left JOINTable2 ontable1.field1 compopr table2.field2 Description: table1, the table2 parameter is used to specify the name of the table to combine the records with. Field1, the Field2 parameter specifies the name of the field being joined.  And these fields must have the same data type and contain the same type of data, but they do not need to have the same name. The COMPOPR parameter specifies the relational comparison operator: "=", "<", ">", "<=", ">=Or<>". If you are joining a field that contains Memo data types or OLE Object data type data in a inner JOIN operation, an error note occurs: Left and right are outer joins, and inner are inner joins. 

Natural connections, external connections, internal connections, the difference between left and right connections (RPM)

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.