DISTINCT results in ORA-01791: not a SELECTed expression

我是研究僧i 提交于 2019-12-28 16:30:24

问题


select DISTINCT a.FNAME||' '||a.LNAME
   from AUTHOR a, books B, BOOKAUTHOR ba, customers C, orders
   where C.firstname='BECCA'
      and C.lastname='NELSON'
      and a.AUTHORID=ba.AUTHORID
      and b.ISBN=bA.ISBN
   order by a.LNAME

gives ORA-01791: not a SELECTed expression but works without DISTINCT.

How to make it work?


回答1:


Just add LNAME as a column on its own in the select clause:

SELECT full_name
FROM (
 select DISTINCT a.FNAME||' '||a.LNAME AS full_name, a.LNAME
 from AUTHOR a, books B, BOOKAUTHOR ba, customers C, orders
 where C.firstname='BECCA'
   and C.lastname='NELSON'
   and a.AUTHORID=ba.AUTHORID
   and b.ISBN=bA.ISBN
 )
order by a.LNAME

If you only want the first column in the output, you can put the whole thing in a subquery.



来源:https://stackoverflow.com/questions/5507060/distinct-results-in-ora-01791-not-a-selected-expression

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!