这是一个粗略的草图。我有一个先决条件表和主题表。我有一个粗略的想法,我可以列出主题代码。但我真的不确定如何获得可以列出主题名称和详细信息的查询,这是先决条件。
例如,我想编写一个查询,列出主题名称及其先决条件名称。所以结果会是(好吧,我稍后会做连接文本):“计算机简介是操作系统的先决条件”。
我只是想知道如何从这两个表中提取主题名称?
CREATE TABLE subjects (
subject_code VARCHAR(7) NOT NULL CONSTRAINT subject_pk PRIMARY KEY,
subject_name VARCHAR(50) NOT NULL,
subject_details TEXT NOT NULL
);
CREATE TABLE SubjectPrerequisite
( Primary_Subject_Code VARCHAR(7) NOT NULL,
Prerequisite_Subject_Code VARCHAR(7) NOT NULL,
CONSTRAINT PK_SubjectPrerequisite PRIMARY KEY (Primary_Subject_Code, Prerequisite_Subject_Code),
CONSTRAINT FK_SubjectPrerequisite_Primary_Subject_Code FOREIGN KEY (Primary_Subject_Code) REFERENCES Subject (Subject_Code),
CONSTRAINT FK_SubjectPrerequisite_Prerequisite_Subject_Code FOREIGN KEY (Prerequisite_Subject_Code) REFERENCES Subject (Subject_Code)
)
//编辑:这是我到目前为止所拥有的
SELECT subject_name
FROM SubjectPreRequisite t0
INNER JOIN subjects t1
ON t0.subject_code = s1.prerequisite_subject_code