Database Operations (III)

Source: Internet
Author: User

1. Internal connection: INNER JOIN

Basic syntax: Select a. column name from table 1 a INNER JOIN table 2 B on a.ID =b.id [and ... inner join table 3 C on ...] where a.name = ' value ';

2. External connection:

(1) Left outer connection: Ieft Join

Select a. column name from table 1 a LEFT JOIN table 2 B on a.ID =b.id and b. Column name = ' value ' [INNER JOIN table 3 C on ...] where a.name = ' value ';

(2) Right outer connection: Starboard Join

Select a. column name from table 1 a right join table 2 B on a.ID =b.id and b. Column name = ' value ' [INNER JOIN table 3 C on ...] where a.name = ' value ';

Note: The and post content is related only to table 2

3. Merging result sets

(1) de-Consolidation: Union

Select Column_names from table 1 union select column_names from table 2;

Note: Table 1 and Table 2 must: the same number of columns, the same order of columns, the same type of columns

Table 1 and Table 2 can: Different column names, directly add data (select 5 as Column name s from table name)

When the column appears aliased: Select Column_names A From table 1 union select Column_names b from table 2;

The output is only related to a

            

(2) Full merger: UNION ALL

Select Column_names A From Table 1 union ALL select Column_names B from table 2 order by column name;

Note: Order BY is written in the last

4. Except: Remove the same data as table 1 that exists in table 2

Select Column_names A From table 1 except select Column_names b from table 2;

Intersect: Take intersection

Select Column_names A From table 1 intersect select Column_names b from table 2;

Database Operations (III)

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.