MySQL link left link right link difference

Source: Internet
Author: User

In MySQL, you can combine data from a relational table into a conditional filter by using an internal and external key link:

First create two new tables with the following data:

Student Table Data:

Score Table Data:

You can see that the records stu_id 16048008 in the students table have no data corresponding to the score table;

1. When an internal connection is made, the system automatically ignores the data that does not correspond to the two tables:

-- Show all data inside the connection: SELECT *  from INNER JOIN  on St.sid=sc.stu_id;

Too much data, only the end:

As you can see, the data is only displayed to 16048007,16048008 and is not displayed, so the inner join only shows all the associated data.

2. Left link, display all the data in the left table of the keyword, the right table data data is less than the null value, the data is not displayed;

-- left outer link SELECT *  from  Left JOIN  on St.sid=sc.stu_id;

As you can see, 16048008 has no data in the right score table, and the system is null-padded,

SELECT *  from  Left JOIN  on St.sid=sc.stu_id;

Is that we will students table and score table for a position of the running results, you can see that the right table 16048008 records, because in the left table clock no data corresponding, so it was deleted, you can see that the left link is the left table in the data as a reference, display all the data on the left table, the right table, Show only the data corresponding to the table on the left, with less fill null, more delete;

Similarly, the right link is to the right of the reference, the left is less than the null, more delete, here is not much to say;

The above can be drawn:

1. Internal connection, showing all the data in the two tables;

2. Left link, with left table as the reference, display all data;

3. Right link, the right table for the reference display data;

MySQL link left link right link difference

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.