我为一个学校项目创建了一些表格。感兴趣的表是
//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 子句中有 weights_subjects_courses,但它不在 from 子句中。每当您在 where 子句中连接表时,您还需要将它们包含在您的 from 子句中。
因此只需将 weights_subjects_courses 添加到您的 from 子句中即可修复该错误。
关于sql - 帮助基本的 SQL QUERY,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5209091/