码迷,mamicode.com
首页 > 其他好文 > 详细

ORA-01791: not a SELECTed expression

时间:2014-05-09 23:42:19      阅读:368      评论:0      收藏:0      [点我收藏+]

标签:c   使用   a   name   res   sql   

Student表有3个字段:id,name,age

看这两个SQL语句

(1)select name from student order by id;

(2)select distinct(name) from student order by id;

执行结果你可能会说:

第1句返回以id排序的所有name字段

第2句返回以id排序的所有不重复的name字段.

但是执行结果不是这样的,第2句会报ORA-01791: not a SELECTed expression

 

原因:

一般来说,order by 的排序字段是可以不出现在select查询字段列表中的,但当查询中使用了DISTINCT或者GROUP BY子句时,order by中的排序字段就必须出现在select列表中,否则就会报上述错误.

 

第2句应改成  select distinct(name),id from student order by id

或者         select distinct(name) from student order by name

ORA-01791: not a SELECTed expression,布布扣,bubuko.com

ORA-01791: not a SELECTed expression

标签:c   使用   a   name   res   sql   

原文地址:http://www.cnblogs.com/rongfengliang/p/3718714.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!