請幫我解決下一個oracle sql查詢問題。Oracle選擇子查詢
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;
當我執行此查詢我有錯誤
ORA-00907: missing right parenthesis
00907. 00000 - "missing right parenthesis"
*Cause:
*Action:
Error at Line: 4 Column: 74
如果意圖是從news_media獲取新聞項目的MIN位置的文件名,我認爲rownum沒有被正確使用。在選擇一條記錄後應用「ORDER BY」。它需要被subqueried,或者更好的是,與MIN(position)分開連接。見http://www.oracle.com/technetwork/issue-archive/2006/06-sep/o56asktom-086197.html – Glenn 2012-08-03 13:25:10