1. Introduction to Connection Query
Join query can be used to query multiple data tables. When the queried field data comes from different tables, join query can be used to complete.
The connection query can be divided into:
① , Internal connection query
② , Left Join Query
③ , Right Join Query
④ , Self Connect Query
2. Inner join query
Query the matching common records in two tables
Effect picture of internal connection query:
Syntax format of inner join query:
SELECT 字段 FROM 表1 INNER JOIN 表2 ON 表1,字段1 = 表2,字段2
explain:
① INNER JOIN is the inner join query keyword
② And ON are connection query conditions
If Field 1 in Table 1 is equal to Field 2 in Table 2, the results can be queried.
Example: Query student table and class table using inner join
SELECT * FROM students INNER JOIN class on students.class=class.className;
Example: Query the class of the student
SELECT students.name,class.className FROM students INNER JOIN class on students.class=class.className;