帮助进行基本的 SQL 查询
我为学校项目创建了一些表格。感兴趣的表是
//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...
^
提前致谢
i have created a few tables for a schoool project. The tables of interest are
//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)
The problem comes when i try the following query
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;
i get this error
SQL error:
ERROR: missing FROM-clause entry for table "weights_subjects_courses"
LINE 1: ...ourses, subjects, weights WHERE courses.courseId= weights_su...
^
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的 where 子句中有weights_subjects_courses,但它不在 from 子句中。每当您在 where 子句中连接表时,您还需要将它们包含在 from 子句中。
因此,只需将weights_subjects_courses 添加到您的from 子句中即可修复该错误。
You have weights_subjects_courses in your where clause, but it's not in the from clause. Whenever you join tables in your where clause, you need to also include them in your from clause.
So just add weights_subjects_courses into your from clause to fix that error.