I can't seem to figure out why this error is occurring.
Here is my code:
SELECT DISTINCT c.cid
FROM customers c
WHERE EXISTS ( SELECT DISTINCT t.aid
FROM transactions t
WHERE EXISTS ( SELECT a.balance
FROM accounts a
WHERE t.cid = c.cid
AND a.aid = t.aid
AND ((sysdate - a.date_opened) > 365)
ORDER BY a.balance DESC
)
);
The error is in the last line.
ORDER BYis inside the innerEXISTS(). Move theORDER BYto the top level. - Michael Berkowski