mysql-Table Connection

Source: Internet
Author: User
Tags one table

MySQL aliases

SELECT concat_ws ('as ' full name ' #CONCAT_WS函数用于字符串的拼接FROM Employees;

Mysql-inner JOIN operation

Description: Matches rows in one table with rows in other tables, and allows querying of row records containing columns from two tables.

INNER JOIN语Before a sentence, you must specify the following conditions:

First, specify the primary table in the FROM statement.

Second, the main table in the table to be connected should appear in the INNER JOIN语 sentence. Theoretically, you can connect multiple other tables. However, to get better performance, you should limit the number of tables you want to connect (preferably not more than three tables).

Third, the connection condition or connection predicate. The join condition appears INNER JOIN after the keyword of the statement ON . A join condition is a rule that matches rows in a primary table with rows in other tables.

Suppose you use a INNER JOIN clause to connect two tables: T1 and T2
SELECT column_listfrom t1inner JOIN T2 on Join_condition;

For t1 each row in the table, the INNER JOIN statement compares it to t2 each row of the table to check whether they satisfy the join condition. When the join condition is met, a new row is returned that consists of the INNER JOIN t1 t2 columns in the table.

Note that the t1 t2 rows in the table and the tables must match according to the join criteria. If no match is found, the query returns an empty result set. 2This logic is also applied when more than one table is connected.

Mysql-left JOIN operation

Features: Querying data from two or more database tables.

Suppose you want to query data from two tables T1 and T2. SELECT     t1.c1, T1.c2, T2.C1, t2.c2from    T1 left        JOIN    = t2.c1;

When you use a statement to join a table to a LEFT JOIN t1 t2 table, the t1 row t1.c1 = t2.c1 t2 is included in the result set if the rows from the left table match the right table based on the join condition ().

If the rows in the left table do not match the rows in the right table, the rows in the left table are also selected and combined with the false rows in the right table. The false row SELECT contains values for all corresponding columns in the clause NULL .

Mysql-cross JOIN operation

功能介绍:CROSS JOIN语A sentence returns the Cartesian Descartes product of a row from a connected table.

Connect two tables: syntax for CROSS join clauses for T1 and T2: SELECT      *from    T1 cross        JOIN    T2;

List all the two sheets.

Result table: Column = The number of columns in the original table is added, row = row number of the original table multiplied

mysql-Table Connection

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.