The difference between left join and right join in MySQL and Inner join and full join

Source: Internet
Author: User

Take a look at the results of the left join and the right join with the Inner join and the full join to manipulate the table.

    • Create a new two table in the database and insert the data you want to test.

New table:

[SQL]View PlainCopy
  1. Use [Test]
  2. GO
  3. /****** object: Table [dbo].[ EMP] Script Date: 06/22/2012 15:37:28 ******/
  4. SET ansi_nulls on
  5. GO
  6. SET quoted_identifier on
  7. GO
  8. CREATE TABLE [dbo].[ EMP] (
  9. [Ename] [nchar] (Ten) COLLATE chinese_prc_ci_as not NULL,
  10. [City] [nchar] (Ten) COLLATE chinese_prc_ci_as NULL
  11. ) on [PRIMARY]


[SQL]View PlainCopy
  1. Use [Test]
  2. GO
  3. /****** object: Table [dbo].[ SAL] Script Date: 06/22/2012 15:38:04 ******/
  4. SET ansi_nulls on
  5. GO
  6. SET quoted_identifier on
  7. GO
  8. CREATE TABLE [dbo].[ SAL] (
  9. [Ename] [nchar] (Ten) COLLATE chinese_prc_ci_as not NULL,
  10. [SALARY] [Money] NULL
  11. ) on [PRIMARY]


Table to insert data from:

EMP Table:

Sal table:

    • left connection [SQL]  view plain copy  
      1. select  *  from emp left join sal  on emp. Ename = sal. ename;  

      Left connection, table EMP is the main table, So the result of the query is to display all the information of the EMP (main table) and the SAL (schedule) information related to the EMP.
    • Right connect [SQL] view plain copy
      1. 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.
    • Internal connection [SQL] view plain copy
      1. SELECT * FROM EMP inner join SAL on EMP. ename = SAL.  ename;

      Link, which displays information related to a table.
    • Full connection [SQL] view plain copy
      1. SELECT * from EMP full join SAL on EMP. ename = SAL.  ename;

      Fully connected, displaying all two tables of information.

The difference between left join and right join in MySQL and Inner join and full join

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.