Mysql left connection right connection internal connection -- Example

Source: Internet
Author: User

Databases are rarely used, and only simple addition, deletion, selection, and modification are allowed. A few days ago, during the interview, I was asked to connect left and right, and then... then there was no more.

I searched some materials online and tried it again. I finally understood it. It is recorded here for future reference.

For more information, see the example.

Below are two tables

Table stu

  

Table tech

  

  

1. Right join

When the right join statement is used for query, the following result is returned:

  stu.id,stu.name,stu.classe_name,tech.id,tech.name  stu   tech  stu.classe_nametech.classe_name;

  

From the results, we can see that all the fields queried in the tech table will be displayed, while in the stu table, only the corresponding fields of the same entries as the classe_name of the tech table will be displayed.

  

  

  stu.id,stu.name,stu.classe_name,tech.id,tech.name  stu   tech  stu.classe_nametech.classe_name;

  

It can be seen from the results that all the queried fields in the stu table will be displayed, while in the tech table, only the corresponding fields of the same entry as the classe_name of the stu table will be displayed.

Left join: return all queried fields in the left table + qualified fields in the right table.

3. Internal Connection

When an internal connection statement is used for query, the following results are returned:

  stu.id,stu.name,stu.classe_name,tech.id,tech.name  stu   tech  stu.classe_nametech.classe_name;

  

From the results, we can see that entries with the same classe_name in the stu and tech tables are displayed.

  

 

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.