Reputation: 1
This is my code and for some reason I keep getting the error that says
Incorrect syntax near the keyword 'where'
I would like to know what I am doing wrong.
select course id, sec id, count(ID) as enrollment
from section natural
join takes
where semester = 'Fall'
and year = 2009
group by course_id, sec_id
Upvotes: 0
Views: 2579
Reputation: 1269563
It is best to avoid natural join
. Because it uses common field names -- and not explicitly defined foreign key relationships -- it is really just a bug waiting to happen.
You would get this problem if your database didn't support natural join
. The natural
would be the table alias for section
in this case. This is just a guess.
I would suggest that you write the query as:
select course_id, sec_id, count(ID) as enrollment
from section s join
takes t
on s.?? = t.??
where semester = 'Fall' and year = 2009
group by course_id, sec_id;
You need to fill in the appropriate columns for the on
clause.
Upvotes: 2