I know this is a duplicate question asked before but the other post doesn't solve my problem.
I am trying to display only the top 2 rows that result from the following query.
SELECT
AVG(sessionprice),
branchsuburb
FROM branch,
sessions
WHERE branch.branchid = sessions.branchid
GROUP BY branchsuburb
ORDER BY AVG(sessionprice) DESC;
That query as is will return all the results but I wish to restrict it to only the top 2 (in terms of which row has the highest average). I tried the fetch function in this post How do I limit the number of rows returned by an Oracle query after ordering? however it simply returns a ORA-00933 error. I know I must be making some silly mistake but I can't figure it out. Is there a way to do this without using a subquery?
The code after adding the fetch function looks like this
SELECT
AVG(SESSIONPRICE),
BRANCHSUBURB
FROM BRANCH,
SESSIONS
WHERE BRANCH.BRANCHID = SESSIONS.BRANCHID
GROUP BY BRANCHSUBURB
ORDER BY AVG(SESSIONPRICE) DESC
FETCH FIRST 2 ROWS ONLY;