web-dev-qa-db-fra.com

DISTINCT entraîne ORA-01791: pas une expression SELECTed

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

donne ORA-01791: pas une expression SELECTed mais fonctionne sans DISTINCT.

Comment le faire fonctionner?

24
user490735

Ajoutez simplement LNAME en tant que colonne à part entière dans la clause select:

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

Si vous ne voulez que la première colonne dans la sortie, vous pouvez mettre le tout dans une sous-requête.

25
Jeffrey Kemp