我想从具有多个外键的多个表中选择 sqlite 的结果,我尝试过JOIN
,但效果不佳;例如 :
一个表STUDENT
:
CREATE TABLE STUDENT (
STUDENT_NAME TEXT NOT NULL,
STUDENT_NUMBER INTEGER PRIMARY KEY NOT NULL,
STUDENT_ADDRESS TEXT NOT NULL
);
和一张桌子EXAMS
:
CREATE TABLE EXAMS(
EXAM_CODE INTEGER PRIMARY KEY NOT NULL,
EXAM_SUBJECT TEXT NOT NULL,
EXAM_LOCATION TEXT NOT NULL
);
和一个表格WROTE_EXAM
,用于获取参加特定考试的学生的信息
CREATE TABLE WROTE_EXAM (
STUDENT_NUMBER INTEGER NOT NULL,
EXAM_CODE INTEGER NOT NULL,
DATE DATE NOT NULL,
FOREIGN KEY(STUDENT_NUMBER) REFERENCES STUDENT(STUDENT_NUMBER),
FOREIGN KEY(EXAM_CODE) REFERENCES EXAMS(EXAM_CODE));
这是插入表中的示例数据:
STUDENT_NAME : John
STUDENT_NUMBER: 123456789
STUDENT_ADDRESS : 10th street
EXAM_CODE: 123
EXAM_SUBJECT: One Subject
EXAM_LOCATION: Class
现在,我想:
a) 输出学生姓名、考试代码和学生位置,谁写了考试
b) 为 ID 为 123456789 的学生输出考试代码、考试科目和考试位置
谢谢