SQL: Left connection, right connection, inner connection

Source: Internet
Author: User

Example:   ----------------------   ---------------------------  a table     ID   name       b table   ID   Job   parent_id              1   Sheets 31     1              2   John Doe 2 2              3   Wang Wu             3    Relationship between a.ID and parent_id in 4--------------------------------------------------

Original table above

1. Left connection:

Official explanation: The LEFT join returns records that include all the records in the left table and the equivalent of the join fields in the right table

Left JOIN connect     Select   a.*,b.*   from   a   left   join   b     on   a.id=b.parent_id         result is       1   Sheet 3                   1     1     2   John Doe 2 2     3   Wang Wu                  null  

2. Right Connection:

Official explanation: Right join returns records that include all records in the right table Uhe and the join fields in the left table are equal

Right connect     Select   a.*,b.*   from   a   to   join   b     on   a.id=b.parent_id         The result is       1   sheets 3                   1     1     2   John Doe                  2 2     null 3     4   

3. Internal connection:

Official explanation: Inner join (equivalent connection) returns two tables this is a line that joins fields that are equal

Internal connection     Select   a.*,b.*   from   a   inner   join   b     on   a.id=b.parent_id         result is       1   Sheet 3                   1     1     2   John Doe                  2     2   

SQL: Left connection, right connection, inner connection

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.