Terence Lyu
Terence Lyu

Reputation: 329

SQL command not properly ended on Live SQL with Subqueries

I get an error

ORA-00933: SQL command not properly ended

when I try to run:

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?

Upvotes: 0

Views: 216

Answers (2)

BengisuY
BengisuY

Reputation: 56

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;

Upvotes: 0

Tanzeel
Tanzeel

Reputation: 33

SELECT Instructor
FROM   (SELECT Instructor,
               Count(candidates.Subject) AS n
        FROM   Subjects
               INNER JOIN candidates
                       ON Subjects.Subject = candidates.Subject
        GROUP  BY Instructor) AS temp; 

Upvotes: 0

Related Questions