Click here to Skip to main content
15,886,919 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SQL
SELECT tbl_Departments.DepartmentID, tbl_Departments.DepartmentName, count(tbl_LabourDetails.DepartmentID ) as labour
FROM tbl_LabourDetails RIGHT OUTER JOIN
tbl_Departments ON tbl_LabourDetails.DepartmentID = tbl_Departments.DepartmentID

I have tried like this but there is an exception:
Column 'tbl_Departments.DepartmentID' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
Posted
Updated 16-Mar-14 1:56am
v2

1 solution

You forgot the GROUP BY clause; add
SQL
GROUP BY tbl_Departments.DepartmentID, tbl_Departments.DepartmentName
 
Share this answer
 
Comments
Maciej Los 16-Mar-14 9:24am    
+5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900