我怎样才能使这个有效?
我有两张桌子:
当然:
课程ID,姓名
前提条件:
课程ID,先决条件
此结果的查询是什么:
+----------+------------+----------+------------+
|Course ID |Name |Prereq ID |Prereq Name |
|1 |Intro into B| | |
|2 |Biology |1 |Intro into B|
|3 |Genetics |1 |Intro into B|
+----------+------------+----------+------------+
答案 0 :(得分:0)
您应该可以使用左join将这两个表拉到一起,例如:
Select c.courseid, c.coursename, p.prere1id, p.preqname
from course as c
left join prereq as p
on c.courseid = p.courseid
答案 1 :(得分:0)
SELECT c.courseId, c.courseName, p.prereqId, pc.courseName
FROM course as c
// joins prerequisites
LEFT JOIN prereq as p on p.courseId=c.courseId
// joins course data to prerequisites
LEFT JOIN course as pc on p.prereqId=pc.courseId