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 :)