¿Podría ayudarme con la siguiente consulta sql de Oracle?Oracle select with subquery
SELECT "NEWS"."NEWSID" as ID,
"NEWS"."SLUG",
"NEWS_TRANSLATION".*,
(SELECT FILENAME FROM NEWS_MEDIA WHERE NEWSID = ID AND rownum <= 1 ORDER BY POSITION ASC) as FILENAME
FROM "NEWS"
INNER JOIN "NEWS_TRANSLATION" ON NEWS.NEWSID = NEWS_TRANSLATION.NEWSID
WHERE (NEWS.PUBLISH = 1) AND (NEWS_TRANSLATION.LANG = :lang)
ORDER BY "NEWS"."NEWSID" DESC;
Cuando ejecuto esta consulta que tienen errores
ORA-00907: missing right parenthesis
00907. 00000 - "missing right parenthesis"
*Cause:
*Action:
Error at Line: 4 Column: 74
Si la intención es obtener el nombre de archivo de la posición MIN para una noticia de news_media, no creo que rownum se esté utilizando correctamente. El "ORDER BY" se aplica después de seleccionar un registro. Tendría que ser sub-consultado o, mejor aún, unido por separado con MIN (posición). Ver http://www.oracle.com/technetwork/issue-archive/2006/06-sep/o56asktom-086197.html – Glenn