Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
493 views
in Technique[技术] by (71.8m points)

oracle10g - DISTINCT results in ORA-01791: not a SELECTed expression

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...