MySQL various federated query statements

Source: Internet
Author: User
Tags joins one table

INNER join (equivalent join) returns only rows with the same join field in two tables
Left JOIN, which returns records that include all records in the left table and the join fields in the right table
Right join returns records that include all the records in the right table and the join fields in the left table

INNER JOIN Syntax:

INNER join joins two datasheet usage:

The code is as follows Copy Code
SELECT * FROM table 1 INNER JOIN table 2 on table 1. Field number = Table 2. Field number

INNER join joins three datasheet usage:

The code is as follows Copy Code
SELECT * FROM (table 1 INNER join table 2 on table 1. Field number = Table 2. Field number) INNER JOIN table 3 on table 1. Field number = Table 3. Field number

INNER join joins four datasheet usage:

The code is as follows Copy Code
SELECT * FROM (table 1 INNER JOIN table 2 on table 1. Field number = Table 2. Field number) INNER join table 3 on table 1. Field number = Table 3. Field number) INNER join table 4 on member. Field number = Table 4.

INNER join joins five datasheet usage:

The code is as follows Copy Code
SELECT * FROM ((table 1 INNER JOIN table 2 on table 1. Field number = Table 2. Field number) INNER join table 3 on table 1. Field number = Table 3. Field number) INNER join table 4 on member. Field number = Table 4. Field No. NER JOIN table 5 on member. Field number = Table 5. Field number

SELECT Tx_txurheber_urheber.uid, Tx_txurheber_urheber.werkxurhadrd_kurzname, Tx_vda_werke.d_werksart
From Tx_txurheber_urheber
INNER JOIN Tx_vda_werke on tx_txurheber_urheber.fk_werk = Tx_vda_werke._pk_werk
and Tx_vda_werke.d_werksart = ' theater '
LIMIT 0, 30

Connection six data table usage: slightly, similar to the above join method, everybody extrapolate bar:

Note:

• In the process of entering letters, be sure to use the English half angle punctuation mark, leave half a space between the words;
• When a table is set up, if one is joined to more than one table, the field in the table must be of the number data type, and the same field in more than one table must be a primary key and an AutoNumber The data type. Otherwise, it is difficult to connect successfully.
• Code Nesting Quick methods: For example, to connect five tables, simply add a front and back bracket to the code that connects the four tables (the parentheses are appended to the from, the parentheses are appended to the end of the code), and then continue with the INNER JOIN table name x on table 1 after the parentheses. Field number = Table x. Field number code, so that you can join the datasheet indefinitely:)

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.