数据库
SELECT t.teacherName,c.CourseName,s.stuName FROM teacher t LEFT JOIN teachercourse tc on t.id =tc.tid
LEFT JOIN course c ON tc.cid =c.id LEFT JOIN studentcourse sc ON sc.cid=c.id LEFT JOIN
student s on s.id=sc.sid WHERE t.teacherName='TOM';
SELECT DISTINCT t.teacherName,s.stuName FROM teacher t LEFT JOIN teachercourse tc on t.id =tc.tid
LEFT JOIN studentcourse sc ON sc.cid=tc.cid LEFT JOIN
student s on s.id=sc.sid WHERE t.teacherName='TOM';
SELECT DISTINCT t.teacherName,s.stuName FROM(SELECT id,teacherName FROM teacher WHERE teacherName ='Jack') t LEFT JOIN teachercourse tc on t.id =tc.tid
LEFT JOIN studentcourse sc ON sc.cid=tc.cid LEFT JOIN
(SELECT id,stuName FROM student WHERE stuName='钱二') s on s.id=sc.sid where IFNULL(s.stuName,'')<>'';
SELECT t.teacherName,c.CourseName FROM teacher t LEFT JOIN teachercourse tc on t.id =tc.tid
LEFT JOIN course c ON tc.cid =c.id WHERE t.teacherName ='Tom';
SELECT c.CourseName,t.teacherName FROM course c LEFT JOIN teachercourse tc on c.id =tc.cid
LEFT JOIN teacher t ON tc.tid=t.id WHERE c.CourseName ='java';
SELECT s.stuName,c.CourseName FROM student s LEFT JOIN studentcourse sc on s.id=sc.sid
LEFT JOIN course c on sc.cid=c.id WHERE s.stuName='钱二';
SELECT c.courseName,s.stuName FROM course c LEFT JOIN studentcourse sc on c.id=sc.cid
LEFT JOIN student s ON sc.sid=s.id WHERE c.CourseName='java';
/*
SELECT s.stuName,c.CourseName FROM (SELECT * FROM student WHERE stuName ='钱二’) LEFT JOIN studentcourse sc ON s.id=sc.sid LEFT JOIN course c ON sc.cid=c.id WHERE s.stuName='钱二';
*/
SELECT * FROM (SELECT * FROM student WHERE stuName = '钱二') s LEFT JOIN studentcourse sc ON s.id = sc.sid LEFT JOIN course c ON sc.cid = c.id