Click here to Skip to main content
15,890,336 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How to SUM data column when join is used?
SQL
SELECT SUM(R.r_LimeGypsum),C.a_pH,C.c_FirstName,R.r_LimeGypsum
FROM dbo.Cultivator_tbl C
LEFT JOIN dbo.Recommendation_tbl R
ON C.Cid=R.Did


I am getting this error:
ERROR:Column 'dbo.Cultivator_tbl.a_pH' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
Posted
Updated 3-Aug-13 3:28am
v2

If you want to display fields along side the aggregate function (SUM[^]) you need to use the GROUP BY[^] clause.

Here is an explanation of the GROUP BY clause: http://www.w3schools.com/sql/sql_groupby.asp[^].

Your statement would become:
SQL
  SELECT SUM(R.r_LimeGypsum),C.a_pH,C.c_FirstName,R.r_LimeGypsum
    FROM dbo.Cultivator_tbl C
    LEFT JOIN dbo.Recommendation_tbl R
           ON C.Cid=R.Did
GROUP BY C.a_pH,C.c_FirstName,R.r_LimeGypsum
 
Share this answer
 
Add the Group By clause as explained in the error message, I am assuming that your statement is correct.

SQL
SELECT SUM(R.r_LimeGypsum),C.a_pH,C.c_FirstName,R.r_LimeGypsum
FROM dbo.Cultivator_tbl C
LEFT JOIN dbo.Recommendation_tbl R
ON C.Cid=R.Did
GROUP BY C.a_pH,C.c_FirstName,R.r_LimeGypsum


[Edit]Follow solution 1 above, there was no solution when adding my solution, he beat me to it, and gave you useful links.[/Edit]
 
Share this answer
 
v2

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