MySQL Database association query "Lert join" common use

Source: Internet
Author: User
Tags joins

One, key words:

1) Left (connection type) join on (condition)

two, common connections:

1) Join (acquisition of a Cartesian product),

SELECT * from T_table1 join T_table2;

2) Left connection (two table associations, after matching criteria, left table remains all, that is, contains no match to the field)

SELECT * from T_table1 LEFT join t_table2 on t_table1.id = t_table2. ID;

3) Right connection (two table associations, after matching criteria, the right table retains all, contains no match to the field)

SELECT * from T_table1 right join t_table2 on t_table1.id = t_table2. ID;

4) Inner connection (get intersection)

SELECT * FROM T_table1 inner join t_table2 on t_table1.id = t_table1. ID;

5) Check only the contents of the left table (two table associations, query the data unique to the left table)

SELECT * from T_table1 left joins t_table2 on t_table1.id = t_table2. ID where t_table2.id is null;

6) Only the right table content (two table association, query the right table unique data)

SELECT * from T_table1 left joins t_table2 on t_table1.id = t_table2. ID where t_table1.id is null;

7) Fully connected

SELECT * from T_table1 LEFT join T_table2 on t_table1. id = t_table2.id

Union

SELECT * from T_table1 right join T_table2 on t_table1. id = t_table2.id;

8) go to the intersection

SELECT * from T_table1 LEFT join t_table2 on t_table1.id = t_table2. ID where t_table2. ID is null

Union

SELECT * from T_table1 right join t_table2 on t_table1.id = t_table2. ID where t_table1. ID is null;

  

MySQL Database association query "Lert join" common use

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.