造成 SQL 中出现“模棱两可的列名”错误的原因是什么,如何修复它?

huangapple go评论148阅读模式
英文:

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

huangapple
  • 本文由 发表于 2023年6月5日 06:23:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/76402635.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定