Various mysql joint query statements

Source: Internet
Author: User

This article briefly introduces the usage of various joint query statements, including inner join, join left, and other multi-table joint queries. If you need them, you can refer to them.

Inner join (equivalent JOIN) returns only rows with equal JOIN fields in two tables.
Left join returns records that include all records in the LEFT table and JOIN fields in the right table.
Right join returns records that include all records in the RIGHT table and the joined fields in the left table.

Inner join Syntax:

Use inner join to JOIN two data tables:

The Code is as follows: Copy code
SELECT * FROM table 1 inner join table 2 ON table 1. Field number = TABLE 2. Field number

Use inner join to JOIN three data tables:

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

Use inner join to JOIN four data tables:

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 number

Use inner join to JOIN Five data tables:

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 number) inner 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

The usage of connecting the six data tables is as follows :)

Note:

• When entering letters, you must use English Punctuation Marks and leave a half-width space between words;
• When creating a data table, if a table is connected to multiple tables, the fields in this table must be of the "Number" data type, and the same fields in multiple tables must be primary keys, the data type is "auto-numbered. Otherwise, it is difficult to connect successfully.
• Code nesting quick method: for example, if you want to connect five tables, you only need to add a bracket to the Code connecting the four tables (the Front Bracket is added after the FROM clause, add the parentheses at the end of the Code), and then add "inner join table name x on table 1. field number = Table X. field number "code, so that you can join the data table without limit :)

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.