INNER JOIN “字段列表”中的未知列

发布于 2024-11-01 03:03:19 字数 400 浏览 2 评论 0原文

我试图显示这些列中的信息,但它一直告诉我教授表中的first_name 列未知。有谁知道为什么? 请帮助我,我已经尝试了一切。 谢谢。

这是查询:

SELECT courses.name, sections.section_name, professors.first_name, professors.last_name, classrooms.room
FROM courses
INNER JOIN course_section ON sections.id = course_section.section_id
INNER JOIN professor_course ON professors.id = professor_course.professor_id
WHERE courses.id = 1;

I'm trying to display the information I have in these columns and it keeps telling me that the first_name column in my professors table is unknown. Does anyone know why?
Please help me, I've tried everything.
Thanks.

Here's the query:

SELECT courses.name, sections.section_name, professors.first_name, professors.last_name, classrooms.room
FROM courses
INNER JOIN course_section ON sections.id = course_section.section_id
INNER JOIN professor_course ON professors.id = professor_course.professor_id
WHERE courses.id = 1;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

花间憩 2024-11-08 03:03:19

该错误是因为您没有在任何fromjoin 中包含部分教授也会发生同样的事情。

就我个人而言,我更喜欢这种情况下隐含内部联接的可读性。 DBA 可能不同意,但作为一名程序员,我发现这更容易弄清楚发生了什么。

SELECT courses.name, sections.section_name, professors.first_name, professors.last_name, classrooms.room 
FROM courses, course_section, sections, professors, professor_course, classrooms
WHERE sections.id = course_section.section_id
AND professors.id = professor_course.professor_id 
AND -- classrooms???
AND courses.id = 1; 

不知道您的数据库结构,您可能可以通过更少的表连接来获得您正在寻找的内容。

The error is because you haven't included sections in any from or join. You have the same thing going on with professors.

Personally, I prefer the readability of implied inner joins in this situation. A DBA may disagree, but as a programmer I find this easier to figure out what's going on.

SELECT courses.name, sections.section_name, professors.first_name, professors.last_name, classrooms.room 
FROM courses, course_section, sections, professors, professor_course, classrooms
WHERE sections.id = course_section.section_id
AND professors.id = professor_course.professor_id 
AND -- classrooms???
AND courses.id = 1; 

Not knowing your DB structure, you can probably get what you are looking for with less table joins.

勿忘心安 2024-11-08 03:03:19

您没有在 FROM 子句中加入 professors 表,您只有 professor_course

You're not joining the professors table in your FROM clause, you only have professor_course.

空袭的梦i 2024-11-08 03:03:19

重新检查数据库,您可能拼错了其中的列。

Recheck the database, you probably misspelled the column in there.

往日情怀 2024-11-08 03:03:19

你有完全错误的查询..

没有这样的表

the tables you need : courses, sections, professors,classrooms

因为你从不同的表(SELECT子句)中进行选择,并且FROMJOIN子句中

 INNER JOIN course_section cs ON sections.id = cs.section_id

在编写上述条件之前,您必须包含表sections

同样的事情,

    INNER JOIN professor_course pc ON professors.id = pc.professor_id 

在编写上述条件之前,您必须包含表professors

我认为您的查询应该是

注意:最好对表使用 别名

ALL D BEST

u have completely wrong Query..

as u r selecting from different tables( SELECT clause) and there is no such table on FROM or JOIN clause

the tables you need : courses, sections, professors,classrooms

in

 INNER JOIN course_section cs ON sections.id = cs.section_id

u must include table sections before writing above condition

same thing for

    INNER JOIN professor_course pc ON professors.id = pc.professor_id 

u must include table professors before writing above condition

i think your Query should be

Note: better to use alias for tables

ALL D BEST

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文