标题:求解:服务器: 消息 301,级别 16 -- 查询中包含不允许的外联接请求
只看楼主
yfnick
Rank: 2
等 级:论坛游民
帖 子:9
专家分:20
注 册:2009-10-15
结帖率:100%
已结贴  问题点数:20 回复次数:2 
求解:服务器: 消息 301,级别 16 -- 查询中包含不允许的外联接请求
写了一条查询语句
select course.name as coursename, score.sid as studentid, student.name as studentname, score.score as score, teacher.name as teachername from score,student,course,teacher where score.cid *= course.cid and score.sid *= student.sid and course.tid *=teacher.tid
SQL Server2000报错 查询中包含不允许的外联接请求

我将左连接的语法换成 left join on之后
select course.name as  '课程名称', score.sid as '学号', student.name as '学生姓名', score.score as '分数', student.college as '所在学院',
teacher.name as '教师姓名' from score left join student on score.sid = student.sid left join course on score.cid = course.cid
 teacher left join course on
course.tid = teacher.tid
仍然报错
服务器: 消息 170,级别 15,状态 1,行 3
第 3 行: 'teacher' 附近有语法错误。

简单描述一下,这个查询用到了四张表,score、course、student和teacher
score表的主键是sid(分数编号),course表的主键是cid(课程编号),student表的主键是sid(学号),teacher表的主键是tid(教师编号)
另外,score表中有cid和sid两个字段,作为外键与course表和student表连接,course表中有tid字段,作为外键与teacher表连接
这个查询需要获取与分数相关的信息,包括课程名(course表的name字段),学号(student表的sid字段),学生姓名(student表的name字段),分数(score表的score字段),教师姓名(teacher表的name字段)
搜索更多相关主题的帖子: teacher 服务器 where 姓名 
2011-05-27 10:47
go2011
Rank: 6Rank: 6
等 级:侠之大者
帖 子:56
专家分:445
注 册:2011-4-21
得分:10 
from 子句改成下面这样试试看

from score left join student on score.sid = student.sid left join course on score.cid = course.cid left join teacher on course.tid = teacher.tid
2011-05-27 16:34
panyanpan
Rank: 7Rank: 7Rank: 7
等 级:黑侠
帖 子:82
专家分:647
注 册:2011-4-6
得分:10 
select course.name as  '课程名称', score.sid as '学号', student.name as '学生姓名', score.score as '分数', student.college as '所在学院',teacher.name as '教师姓名'
from student left join score on student.sid=score.sid left join course on score.cid =course.cid left join teacher on course.tid=teacher.tid
2011-05-28 09:37



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-341123-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.177062 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved