Web/DataBase

[SQL] ERROR 1055 (42000): Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'TESTDB.teaches.course_id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full..

SweetDev 2022. 10. 14. 20:47

이런 에러를 겪었는데, 

GROUP BY를 사용하는 경우, SELECT할 수 있는 컬럼은 GROUP BY에 나열된 컬럼과 SUM(), COUNT() 같은 집계 함수(Aggregation Function)으로 한정 한다고 한다....!!! (sql 표준 문법은 group by 사용시 select 의 칼럼중 집계함수에 쓰이는 것을 제외한 모든 칼럼을 기입해야 한다. 왜??)

 

해결 방법은, sql_mode 에서 ONLY_FULL_GROUP_BY 설정을 뺀다 

SET SESSION sql_mode = 'NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES';


    - 설정파일(my.cnf)에서 ONLY_FULL_GROUP_BY 를 찾아 삭제한다.