[英]Column 'SSN' in field list is ambiguous
I have three tables viz- Student,Enrolls and Course.我有三个表,即学生、注册和课程。 I wanted to fetch the information about students (their SSN,First and Last Names) who took course as Computer Architecture.我想获取有关参加计算机体系结构课程的学生的信息(他们的 SSN、名字和姓氏)。
I wrote a query like我写了一个查询
select SSN,First_Name,Last_Name,Course_Name='Computer Architecture'
from STUDENT s,ENROLLS e,COURSE c where s.SSN=e.SSN and e.CourseNo=c.CourseNo;
and got an error saying:并得到一个错误说:
ERROR 1052 (23000): Column 'SSN' in field list is ambiguous错误 1052 (23000):字段列表中的列“SSN”不明确
My table structure is as follows我的表结构如下
Student(SSN,First_Name,Last_Name,Street,City,Zip,State)
Course(CourseNo,Course_Name,Department)
Enrolls(SSN,SectionNo,CourseNo)
Where am I getting it wrong?我在哪里弄错了?
You add simply the alias name in forint of it and so it becomes unambiguously您只需在它的福林中添加别名,因此它变得明确
I also changed it to JOINs, your method is since many years outdated我也把它改成了JOINs,你的方法已经过时了很多年
SELECT
e.SSN,
First_Name,
Last_Name,
Course_Name = 'Computer Architecture'
FROM
STUDENT s
INNER JOIN
ENROLLS e ON s.SSN = e.SSN
INNER JOIN
COURSE c ON e.CourseNo = c.CourseNo;
SQL supports qualifying a column by prefixing the reference with either the full table name or table alias: SQL 支持通过在引用前面加上完整的表名或表别名来限定列:
SELECT
e.SSN,
First_Name,
Last_Name,
Course_Name = 'Computer Architecture'
FROM STUDENT s
JOIN
ENROLLS e ON s.SSN = e.SSN
JOIN
COURSE c ON e.CourseNo = c.CourseNo;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.