When we usually use a database, it is impossible to check only one table. When we want to combine multiple tables for query, we need to perform multi-table query.
Let's design 4 interrelated tables:
Then we now use the Cartesian product to query the scores of z1's analog and digital circuits:
mysql> select * from class,course,score,student where student.studentId = score.studentId and course.courseId = score.courseId
-> and class.classId = student.studentClassId
-> and studentName = 'z1'
-> and course.courseName = '模拟电路与数字电路';
+---------+-----------+----------+--------------------+-----------+----------+-------+-----------+-------------+----------------+
| classId | className | courseId | courseName | studentId | courseId | score | studentId | studentName | studentClassId |
+---------+-----------+----------+--------------------+-----------+----------+-------+-----------+-------------+----------------+
| 1 | 计算机1班 | 1 | 模拟电路与数字电路 | 1 | 1 | 78 | 1 | z1 | 1 |
+---------+-----------+----------+--------------------+-----------+----------+-------+-----------+-------------+----------------+
1 row in set (0.00 sec)
The red part in front is the multi-table union. Then we are doing data screening.