Multi-table query for SQL database

Source: Internet
Author: User
Tags joins one table

Multi-table queries are divided into internal and external connections

The outer joins are left-connected (either to the right join or to the outer join), to the connection to the starboard join, or to the outer join, and to the full outer join (either the complete join or the outer join)

The result of a LEFT join (left JOIN, or outer join) is that all rows of the leftmost table in the RIGHT join clause, not just the rows that match the linked column, and if a row in the left table does not match in the right table, all selection columns in the table in the associated result row are null values (NULL)

SQL Syntax select * FROM table1 left joins table2 on table1. Condition column name = table2. Condition column name;

Note: All columns and matching columns are displayed in the Table1

Right-join--outer join is not a long way to say this left connection is very much like but the opposite, just say the syntax

Select *from table1 right joins table2 on Table1. Condition column = table2. Condition column

Complete external connection (full join or outer join)

Displays all rows in the left and right table, and when there is no matching row in one table, the selection list column of the other table contains a null value (NULL) if there is one, all data is displayed

SQL syntax:

Select *from table1 full join table2 on table1. Condition column name = table2. Condition Column Name

Internal connection:
Concept: An inner join is a comparison operator that compares the connection to the value of a connection column

INNER JOIN (join or INNER join)

SQL syntax:

Select *fron table1 join table2 on table1. Condition column name = table2. Condition Column Name

Returns two table columns that match the matching criteria

Equivalent to:

Select a *, b* from table1 A, table2 B where A. Condition column name =b. Condition Column Name

Select *form table1 Cross join table2 where table1. Condition column name = table2. Condition column Name (note: The Cross join cannot be followed by on with where)

Cross Connect (Full)

Concept: A cross join without a WHERE clause will result in the number of rows in the first table of the Cartesian product involved in the connection, multiplied by the number of rows in the second table equal to the Cartesian product and the size of the result set

Cross-Joins: crosses join (without a condition where if the band Returns or shows the number of matching rows)

SQL syntax:

Select *from table1 Cross join Table2

If there is a condition (where)

SELECT * FROM table1 cross join Table2 where table1. Condition column name = table2. Condition Column Name

Equivalent to

Select *from table1,table2 (without where)

Multi-table query for SQL database

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.