英文:
What is causing the 'ambiguous column name' error in SQL and how to fix it?
问题
我在我的 SQL 中遇到了问题,不知道该如何解决。
有人能提供一些帮助和提示吗?
字段列表中的 'student_id' 在字段列表中是模糊的
SELECT student_id, student.first_name, student.last_name, subject.label, student_score
FROM score
INNER JOIN student as stdtab on stdtab.id = student_id
INNER JOIN subject as stab on stab.id = subject_id
英文:
Im having problems on my sql and dont know how to fix it.
Can anyone provide some help and tips for it?
Column 'student_id' in field list is ambiguous
SELECT student_id, student.first_name, student.last_name, subject.label, student_score
FROM score
INNER JOIN student as stdtab on stdtab.id = student_id
INNER JOIN subject as stab on stab.id = subject_id
答案1
得分: 1
这个错误意味着查询中存在多个表中都存在student_id
列名,请在student_id
之前使用表名。就像这样(如果student_id
在名为student
的表中):
SELECT student.student_id, student.first_name, student.last_name, subject.label, student_score
FROM score
INNER JOIN student as stdtab on stdtab.id = student.student_id
INNER JOIN subject as stab on stab.id = subject_id
英文:
This error means the student_id
column name exists in more then one table in the query, use the table name before student_id
. Like this (if student_id
is in table student
):
SELECT student.student_id, student.first_name, student.last_name, subject.label, student_score
FROM score
INNER JOIN student as stdtab on stdtab.id = student.student_id
INNER JOIN subject as stab on stab.id = subject_id
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论