Usage of joins in SQL Server

Source: Internet
Author: User

join is divided into: inner join (INNER join), outer join (OUTER join). Among them, the outer join is divided into: left outer connection (OUTER join), right outer join (OUTER join), full outer join (complete OUTER join), where the "OUTER" keyword of the outer connection can be omitted from writing.
Example: table A has column ID, the value is: 1 2 3 4
Table B has column IDs, with values of: 3 4 5 6
1. Internal connection (shows the data that the left and right two tables can match exactly):

Select a.ID, b.id from A INNER JOIN B on a.id = b.id

The result is: 3 3 4 4
2. Left outer connection (displays all data on the left table, the right table does not match the display as NULL):

Select a.ID, b.id from A left JOIN B on a.id = b.id

Result: 1 null 2 NULL 3 3 4 4
3. Right outer connection (displays all data in the right table, the left table does not match the display as NULL):

Select a.ID, b.id from A right JOIN B on a.id = b.id

Result: 3 3 4 4 null 5 NULL 6
4. Full outer connection (displays all data on both the left and right sides of the table, NULL if the two tables do not match):

Select a.ID, b.id from A full OUTER JOIN B on a.id = b.id

Result: 1 null 2 NULL 3 3 4 4 null 5 NULL 6

Usage of joins in SQL Server

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.