The order by clause is not allowed in a subquery
As mathguy has indicated, the order by clause causes the error to be thrown and it does not serve any purpose.
After looking at your query, I suspect you want to do a correlated subquery (use values from an outer query in the inner (sub) query).
Below using the sample schema emp and dept (which looks a lot like your tables), I specifically select the smallest salary for a given department because of the condition, e1.deptno = e.deptno
.
Specifically, you are probably concerned with the smallest salary associated with a given department.
SCOTT@dev>SELECT
2 e.ename,
3 e.sal,
4 d.*
5 FROM
6 emp e
7 JOIN dept d ON e.deptno = d.deptno
8 WHERE
9 1 = 1
10 AND
11 e.sal IN (
12 SELECT
13 MIN(e1.sal)
14 FROM
15 emp e1
16 WHERE
17 e1.deptno = e.deptno
18 )
19 ORDER BY d.deptno;
ENAME SAL DEPTNO DNAME LOC
MILLER 1300 10 ACCOUNTING NEW YORK
SMITH 800 20 RESEARCH DALLAS
JAMES 950 30 SALES CHICAGO