The difference between the left join of SQL, right join, INNER join

Source: Internet
Author: User
Tags null null

Long time no contact with this query, since the switch software implementation, and understand the next.

This article transferred from: http://www.cnblogs.com/pcjim/articles/799302.html

Find this blog explained most clearly

left join returns records that include all records in the left table and the equivalent of the junction fields in the right table. The right join returns records that include all records in the right table and the equivalent of the junction fields in the left table inner join (equivalent connection) The only rows that return the equivalent of the junction fields in two tables are as follows:--------------------------------------------Table A is recorded as follows: AID Anum1a200501112a200501123a200501134a200501145a20050115 table B is recorded as follows: BID bname1 20060324012 20060324023 20060324034 20060324048 2006032408------------------------------------------ --1The . Left Joinsql statement is as follows: Select*From Aleft join B on A.aid=b.bid results are as follows: AID anum BID bname1 a20050111 1 20060324012 a20050112 2 20060324023 a20050113 3 20060324034 a20050114 4 20060324045a20050115 NULL null (the number of rows affected is5rows) The results show that the left join is based on the records of a table, a can be regarded as the right table, and B can be regarded as 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.--------------------------------------------2The . Right Joinsql statement is as follows: Select*From aright join B on A.aid=b.bid results are as follows: AID anum BID bname1 a20050111 1 20060324012 a20050112 2 20060324023 a20050113 3 20060324034 a20050114 4 2006032404NULL NULL8 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.--------------------------------------------3The . Inner Joinsql statement is as follows: Select*From ainnerjoin B on A.aid=b.bid results are as follows: AID anum BID bname1 a20050111 1 20060324012 a20050112 2 20060324023 a20050113 3 20060324034 a20050114 4 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.--------------------------------------------Note: The LEFT JOIN operation is used to combine records from the source table in any from clause. Use the left JOIN operation to create an outer join of the side. 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: from table1 left JOIN table2 on table1.field1 compopr table2.field2 Description: table1, table2 parameter specifies 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 in a inner JOIN operation that contains data of Memo data type or OLE Object data type, an error occurs. 

The difference between the left join of SQL, right join, INNER join

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.