Cratylus
Cratylus

Reputation: 54094

Why does this statement work when it is part of a subquery?

I see that this SQL statement works:

SELECT * 
FROM Company 
LEFT JOIN (
   Departments 
   INNER JOIN Employees 
   ON Departments.dep_id = Employees.Dep_ID
   ) ON Company.compId = Departments.Comp_ID;  

But this statement:

 Departments INNER JOIN Employees ON Departments.dep_id = Employees.Dep_ID

can not be parsed.

Is this meant to be a short version only for subqueries?

Upvotes: 0

Views: 64

Answers (2)

Dan Bracuk
Dan Bracuk

Reputation: 20804

This:

Departments INNER JOIN Employees ON Departments.dep_id = Employees.Dep_ID

cannot be parsed because it is not a complete query. It is missing the opening clause, which in this case is a select clause. Other options for an opening clause are insert, update, or delete.

It is also missing the keyword "from". Also, while not mandatory, most select queries have a where clause to get just the records they want, as opposed to the entire database.

Upvotes: 3

Matthias W.
Matthias W.

Reputation: 1077

You could be missing "SELECT FROM "?

Upvotes: 1

Related Questions