基本SQL查询帮助
我为一个School项目创建了几个表。兴趣表是基本SQL查询帮助,sql,postgresql,Sql,Postgresql,我为一个School项目创建了几个表。兴趣表是 //table courses CREATE TABLE courses(courseId SERIAL PRIMARY KEY, facultyId REFERENCES faculties(facultyId), courseName TEXT); //table weights CREATE TABLE weights(weightId SERIAL P
//table courses
CREATE TABLE courses(courseId SERIAL PRIMARY KEY, facultyId REFERENCES faculties(facultyId), courseName TEXT);
//table weights
CREATE TABLE weights(weightId SERIAL PRIMARY KEY, weightName TEXT, weight INTEGER);
//table subjects
CREATE TABLE subjects(subjectId SERIAL PRIMARY KEY, subjectName TEXT);
//table weights_subjects_courses
CREATE TABLE weights_subjects_courses(courseId integer REFERENCES courses(courseId), weightId integer REFERENCES weights(weightId), subjectId integer REFERENCES subjects(subjectId)
当我尝试下面的查询时,问题出现了
SELECT * FROM courses, subjects, weights WHERE courses.courseId= weights_subjects_courses.courseId AND subjects.subjectId= weights_subjects_courses.subjectId AND weights.weightId= weights_subjects_courses.weightId ORDER BY courseName;
我得到这个错误
SQL错误:
ERROR: missing FROM-clause entry for table "weights_subjects_courses"
LINE 1: ...ourses, subjects, weights WHERE courses.courseId= weights_su...
^
提前感谢您的where子句中有权重科目,但from子句中没有权重科目。无论何时在where子句中联接表,都需要将它们包括在from子句中
所以只需在from子句中添加权重、科目和课程,即可修复该错误 “无论何时在where子句中加入表,都需要将它们包括在from子句中。”谢谢:)任何时候,我想这只是一个疏忽;)