Usage of visual charts in MySQL and tips for multi-table INNERJOIN
Create View
SQL code
CREATE VIEW view_name AS SELECT t1.xxx, t2.xxx, t3.xxx FROM (table1 t1 INNER JOIN table2 t2 ON t1.fid = t2.fid) INNER JOIN table3 t3 ON t1.mid = t3.mid;
Three table associations are used here. there is a skill for writing multi-table join inner join statements.
1. first write the simplest 2-table JOIN INNER JOIN
2. then use () to expand FROM the back of FROM to the end of the statement.
3. start JOIN at the end of the statement to the inner join of the next table
Keep in mind this principle. in the future, it will not be difficult to associate four tables and five tables.
Delete View
The code is as follows:
Drop view view_name
The following is a supplement from other netizens:
Multi-table join is very useful because in some cases, we need to query data across multiple tables.
Syntax format:
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 x on Member. field Number = table X. field Number. you only need to apply this format.
Note:
When you enter a letter, make sure to use the English punctuation marks. leave a space in half 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, it is also an "automatic serial number" data type. 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, 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 infinitely.
How to connect two data tables:
FROM Table 1 inner join Table 2 ON Table 1. Field number = Table 2. Field number
How to connect three data tables:
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
Usage of connecting four data tables:
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
Usage of connecting five data tables:
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