I get an error
ORA-00933: SQL command not properly ended
when I try to run:
x
select Instructor
from
(select Instructor, count(candidates.Subject) as n
from Subjects, candidates
where Subjects.Subject = candidates.Subject
group by Instructor) as temp;
However, the subquery
select Instructor, count(candidates.Subject) as n
from Subjects, candidates
where Subjects.Subject = candidates.Subject
group by Instructor;
can be run without a problem.
I am not sure where I did wrong.
I found that doing the query without a alias works. Why is that?
Advertisement
Answer
You have to remove the “AS” before TEMP. Because “AS” cannot come after “FROM” keyword.
SELECT INSTRUCTOR
FROM ( SELECT INSTRUCTOR, COUNT (CANDIDATES.SUBJECT) AS N
FROM SUBJECTS, CANDIDATES
WHERE SUBJECTS.SUBJECT = CANDIDATES.SUBJECT
GROUP BY INSTRUCTOR) TEMP;