Alter table student; (student. Cid is not set up foreign key associated with the class. The cid) + -- -- -- -- -- -- -- + + -- -- -- -- -- -- -- -- -- - + -- -- -- -- - + -- -- -- -- -- + | name | age | sex | sid | cid | +-------+-----+-----+-----+-----+ | Cindy | 18 | F | 1 | 1 | | Alice | 20 | M | 2 | 2 | | Mike | 19 | F | 3 | 4 | +-------+-----+-----+-----+-----+ class Table data is as follows: +-----------+--------+------+-----+ | classname | grade | num | cid | +-----------+--------+------+-----+ | class1 | grade1 | 40 | 1 | | class2 | grade1 | 38 | 2 | | class3 | grade1 | 37 | 3 | +-----------+--------+------+-----+ Select * from class,student; Or select * from class inner join student + -- -- -- -- -- -- -- -- -- -- - + + -- -- -- -- -- -- -- -- -- -- -- -- -- - + + -- -- -- -- -- -- -- -- -- -- - + -- -- -- -- -- + + -- -- -- -- -- -- -- -- -- - + -- -- -- -- -- + | classname | grade | num | cid | name | age | sex | sid | cid | +-----------+--------+------+-----+-------+-----+-----+-----+-----+ | class1 | grade1 | 40 | 1 | Cindy | 18 | F | 1 | 1 | | class2 | grade1 | 38 | 2 | Cindy | 18 | F | 1 | 1 | | class3 | grade1 | 37 | 3 | Cindy | 18 | F | 1 | 1 | | class1 | grade1 | 40 | 1 | Alice | 20 | M | 2 | 2 | | class2 | grade1 | 38 | 2 | Alice | 20 | M | 2 | 2 | | class3 | grade1 | 37 | 3 | Alice | 20 | M | 2 | 2 | | class1 | grade1 | 40 | 1 | Mike | 19 | F | 3 | 4 | | class2 | grade1 | 38 | 2 | Mike | 19 | F | 3 | 4 | | class3 | grade1 | 37 | 3 | Mike | 19 | F | 3 | 4 | + -- -- -- -- -- -- -- -- -- -- - + + -- -- -- -- -- -- -- -- -- -- -- -- -- - + + -- -- -- -- -- -- -- -- -- -- -- -- + + -- -- -- -- -- -- -- -- -- -- + + -- -- -- -- -- -- -- -- -- -- + two table data from the query results will be combined together, a total of 3 * 3 = 9 records. Inner join left join right join student left join left join right join Select student.sid from inner join where cid = 1 select student.sid from inner join where CID = 1 student.name,class.cid,class.classname,class.grade from class inner join student on class.cid=student.cid; Select student.sid from student.sid; student.name,class.cid,class.classname,class.grade from class,student where class.cid=student.cid; +-----+-------+-----+-----------+--------+ | sid | name | cid | classname | grade | +-----+-------+-----+-----------+--------+ | 1 | Cindy | 1 | class1 | grade1 | | 2 | Alice | 2 | class2 | grade1 | + + -- -- -- -- -- -- -- -- -- -- -- -- + + -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - + -- -- -- -- -- -- -- -- + 2, left the join - as listed in the left link button, keep all records, Select student.sid from student.sid where cid = 0; student.name,class.cid,class.classname,class.grade from class left join student on class.cid=student.cid; +------+-------+-----+-----------+--------+ | sid | name | cid | classname | grade | +------+-------+-----+-----------+--------+ | 1 | Cindy | 1 | class1 | grade1 | | 2 | Alice | 2 | class2 | grade1 | | NULL | NULL | 3 | class3 | grade1 | + -- -- -- -- -- - + -- -- -- -- -- -- -- + + -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - + -- -- -- -- -- -- -- -- + 3, right join - right table as link button, keep all records, Select student.sid from student.sid where cid = 1; student.name,class.cid,class.classname,class.grade from class right join student on class.cid=student.cid; +-----+-------+------+-----------+--------+ | sid | name | cid | classname | grade | +-----+-------+------+-----------+--------+ | 1 | Cindy | 1 | class1 | grade1 | | 2 | Alice | 2 | class2 | grade1 | | 3 | | NULL Mike | NULL | NULL | + + -- -- -- -- -- -- -- -- -- -- - + -- -- -- -- -- - + -- -- -- -- -- -- -- -- -- -- - + -- -- -- -- -- -- -- - + 4, full join - MySQL don't have the key, the union keywords are available, and Implement left JOIN and right Join data setsCopy the code