Link to home
Avatar of Sim1980

asked on

Not showing some records in SQL Select statement

Hi all.

I have the following SELECT statement:

SELECT Builder, Community, Charts,Concat(Users.firstname, ' ', Users.lastname) As Super, Concat(ProjectManagers.FirstName, ' ', ProjectManagers.LastName) As ProjectManager, Concat(Salesperson.FirstName, ' ', Salesperson.LastName) As Salesperson,
   SUM(CASE WHEN FieldSuperDataEntry.Type=1 THEN 1 ELSE 0 END) as Slabs, 
   SUM(CASE WHEN FieldSuperDataEntry.Type=2 THEN 1 ELSE 0 END) as DriedIn,
   COUNT(FieldSuperDataEntry.Type) as TotalCombined
FROM BuilderCommunity LEFT OUTER JOIN FieldSuperDataEntry  ON BuilderCommunity.BuilderCommunityID = FieldSuperDataEntry.BuilderCommunityID LEFT OUTER JOIN FieldSuperAssignment ON BuilderCommunity.BuilderCommunityID = FieldSuperAssignment.BuilderCommunityID LEFT OUTER JOIN Users ON FieldSuperAssignment.UserID = Users.userid LEFT OUTER JOIN ProjectManagerAssignment ON BuilderCommunity.BuilderCommunityID = ProjectManagerAssignment.BuilderCommunityID LEFT OUTER JOIN ProjectManagers ON ProjectManagerAssignment.ProjectManagerID = ProjectManagers.ProjectManagerID LEFT OUTER JOIN SalespersonAssignment ON BuilderCommunity.BuilderCommunityID = SalespersonAssignment.BuilderCommunityID LEFT OUTER JOIN Salesperson ON SalespersonAssignment.SalesPersonID = Salesperson.SalesPersonID LEFT OUTER JOIN JobType ON FieldSuperDataEntry.Type = JobType.jobtypeid WHERE FieldSuperDataEntry.CompletedFloorJob IS NULL AND FieldSuperDataEntry.Status IS NULL  AND BuilderCommunity.Status = 'Active'   
GROUP BY Builder, Community, Super, ProjectManager, SalesPerson
ORDER BY Builder, Community, Super, ProjectManager, Salesperson

Open in new window

It shows all of the counts for each community unless there is a community where ALL of it's data in the FieldSuperDataEntry table has either FieldSuperDataEntry.CompletedFloorJob = 'Completed' or FieldSuperDataEntry.Status = 'Completed', with these communities, they are NOT INCLUDED in the results. They should be included but with Slabs = 0, DriedIn = 0 and TotalCombined = 0.

Now, if a community does not have any data in the FieldSuperDataEntry table, then they are correctly appearing in the results with Slabs = 0, DriedIn = 0 and TotalCombined = 0.

How can I change my select statement to include ALL communities even those where all of it's data in the FieldSuperDataEntry table is already completed?

Thank you in advance.
Avatar of Ganapathi
Flag of India image

Blurred text
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Sim1980


Thanks! I have to do the same thing for our MySQL database, but I know FULL OUTER JOIN doesn't exist in MySQL so I'll post another question.