Reputation: 43
I'm using the following Select statement to retrieve and count the total of each field across multiple tables. However when it comes to executing the statement i get the error "Syntax Error at or near the word join"
Any help would be greatly appreciated
Query:
Select CompanyStatus,Companyname,
INNER JOIN Company on usersincompany.companyID=company.companyID,
INNER JOIN company on users.companyID=Company.companyID,
INNER JOIN usersincompany on users.userid=usersincompany.userid,
INNER JOIN users on userstatus.userstatudid=users.userstatusid,
INNER JOIN users on project.companyid=users.companyid,
INNER JOIN users on usersession.userid=users.userid,
INNER JOIN project on template.projectid=project.projectid,
INNER JOIN project on merchendisingarea.projectid=project.projectid,
INNER JOIN merchendisingarea on publishstatus.publishstatusid=merchendisingarea.publishstatusid,
INNER JOIN template on merchendisingmodule.templateid=template.templateid,
INNER JOIN company on companyaccountclassification.classificationtypeid=company.classificationtypeid,
sum(distinct users.userid) as TotalUsers,
sum(case when users.userstatusid =2 then 1 else 0 end) as Activeusers,
sum(case when users.userstatusid =3 then 1 else 0 end) as SuspendedUsers,
sum(distinct usersessionid) as TotalLogin,
sum(distinct merchendisingmoduleid) as CurrentModules,
count( merchendisingmodule.createddate) as Modulescreated,
count( merchendisingmodule.updateddate) as Modulesupdated,
sum(distinct merchendisingareaid) as Currentareas,
count( merchendisingarea.createddate) as AreasCreated,
count( merchendisingarea.updateddate) as Areasupdated,
sum(case when publishingstatus.publishstatusid =1 then 1 else 0 end) as SuccessPublished,
sum(case when publishingstatus.publishstatusid =3 then 1 else 0 end) as FailedPublished
from users,company,merchendisingmodule,merchendisingarea,publishingstatus, usersession group by companystatus, companyname
Upvotes: 2
Views: 17857
Reputation: 587
Why are there ',' between each joins? No commas needed!
Put it like:
SELECT <COLUMNS>
FROM <TABLE1>
INNER JOIN <TABLE2> ON <JOIN FIELDS>
INNER JOIN <TABLE3> ON <JOIN FIELDS>
WHERE <FILTER CONDITIONS>
Upvotes: 6
Reputation: 3078
You are missing From clause in your query after Companyname
Select CompanyStatus, Companyname .
^ from clause
General syntax for join is as ,
select column_name
from Table_name 1
Inner/Left/Right/cross Join Table_name 2
ON condition
Upvotes: 0
Reputation: 27247
You need a base table to join on!
Select
CompanyStatus,
Companyname,
INNER JOIN Compan...
Needs a first table
Select
CompanyStatus,
Companyname
FROM some_table
INNER JOIN Compan...
And also get rid of those commas!
Upvotes: 0