日期:2014-05-17  浏览次数:20400 次

比较两sql文的查询结果有什么区别 马上结贴
select top 100 teststudent.testarrangeid,teststudent.studentuserid,teststudent.paperid,answersheet.studentid,answersheet.score,answersheet.studentname,answersheet.paperid,u.usercode,u.chinesename as truename,paper.paperdesignid from teststudent 
inner join userinfo u on teststudent.studentuserid=u.userid 
left join answersheet on u.name=answersheet.studentid and answersheet.paperid=teststudent.paperid  
inner join paper on paper.paperid=teststudent.paperid  
where teststudent.paperid=32  
----------------------------------------
select top 100 teststudent.studentuserid from teststudent 
inner join userinfo u on teststudent.studentuserid=u.userid 
left join answersheet on u.name=answersheet.studentid and answersheet.paperid=teststudent.paperid  
inner join paper on paper.paperid=teststudent.paperid  
where teststudent.paperid=32  

第一个查询结果:
SQL code
testarrangeid studentuserid paperid     studentid            score                                                 studentname                    paperid     usercode                                                                                             truename                                           paperdesignid 
------------- ------------- ----------- -------------------- ----------------------------------------------------- ------------------------------ ----------- ---------------------------------------------------------------- -------------------------------------------------- ------------- 
28            1036          32          S1132012147          54.0                                                  NULL                           32          1132012147                                                                                           戴翠叶                                                33
28            1075          32          S1132012227          73.0                                                  NULL                           32          1132012227                                                                                           廖荣华                                                33
28            9198          32          S1101092133          76.0                                                  NULL                           32          1101092133                                                                                           柴琳                                                 33
28            9199          32          S1101092134          74.0                                                  NULL                           32          1101092134                                                                                           王艺                                                 33
28            9200          32          S1101092135          62.0                                                  NULL                           32          1101092135                                                                                           孙萌                                                 33
28            9201          32          S1101092136          81.0                                                  NULL                           32          1101092136                                                                                           王晶                                                 33

第二个查询结果:
studentuserid 
------------- 
1036
1075
2484
2558
2583
2611
只要注意 studentuserid 字段, 看区别, 为什么会这样?

------解决方案--------------------
Order by 唯一属性
------解决方案--------------------