sql group by with left join

fail statement:Error: ORA-00979: not a GROUP BY expression
 select org_division.name  , org_department.name , org_surveylog.division_code as divisionCode,org_surveylog.department_code as departmentCode , max(org_surveylog.actiondate) from org_surveylog 
left join org_division on (org_surveylog.division_code= org_division.division_code and org_surveylog.SURVEY_NUM= org_division.survey_num)
left join org_department on (org_surveylog.department_code = org_department.department_code and org_surveylog.SURVEY_NUM = org_department.survey_num) 
 group by org_surveylog.division_code,org_surveylog.department_code 
but below is ok
 select org_surveylog.division_code as divisionCode,org_surveylog.department_code as departmentCode , max(org_surveylog.actiondate) from org_surveylog 
left join org_division on (org_surveylog.division_code= org_division.division_code and org_surveylog.SURVEY_NUM= org_division.survey_num)
left join org_department on (org_surveylog.department_code = org_department.department_code and org_surveylog.SURVEY_NUM = org_department.survey_num) 
 group by org_surveylog.division_code,org_surveylog.department_code 

how to use group by with left join when i need to show value of org_division.name , org_department.name ?

Answers


You need to change your GROUP BY to

 group by   org_division.name , 
            org_department.name
            org_surveylog.division_code,
            org_surveylog.department_code 

From Oracle Select Statements : Select Statement With GROUP BY Clause

SELECT <column_name>, <aggregating_operation>
FROM <table_name>
GROUP BY <column_name>;

You will notice that you need to include the non aggregated columns in the GROUP BY statement.


Need Your Help

Generate HTML file from HTML form

php html templates

I have created a responsive email "template" that I use at work where we create anywhere from 5 to 40 emails a month. It has become a hassle to change out the text every time I have a new client to