Left JOIN, right join, Inner join and ful join in SQL

Source: Internet
Author: User

1 LEFT JOIN: The query results are based on the left table data. If the left table has four data, the right table has three data, the query result is four, and all the data in the left table.

For example:

EMP Table:

Sal table:

Left connection

Select * from EMP left join SAL on EMP. ename = SAL.  ename;


Left JOIN, the table EMP is the primary table, so the query results show all the information of the EMP (primary table) and the SAL (schedule) information related to EMP.

2 Right OUTER join: The query results are based on the right table data. If the left table has four data, the right table has three data, the query result is three, and all the data in the right table.

Such as:

Select  *  from EMP Right Join SAL on EMP. ename = SAL.  ename;


Right connection, table Sal is the primary table, so the query results show all the information of the salt (the primary table) and the EMP (schedule) and the information that Sal wants to close.

3 INNER JOIN Link: Two table data prevail. The query results are data for both tables.

SELECT  *  from EMP Inner Join SAL on EMP. ename = SAL.  ename;


Link, which displays information related to a table.

4 Full Join All Links: Query results for all data in two tables

SELECT  *  from EMP Full Join SAL on EMP. ename = SAL.  ename;


Fully connected, displaying all two tables of information.

Description: This article is derived from Shadowyelling's column

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.