Error/Database
[MySQL]this is incompatible with sql_mode=only_full_group_by
dev?
2024. 5. 30. 13:28
반응형
org.springframework.jdbc.BadSqlGrammarException:
### Error querying database.
Cause: java.sql.SQLSyntaxErrorException:
Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column
'DB명.테이블 별칭.컬럼명' which is not functionally dependent on columns in GROUP BY
clause; this is incompatible with sql_mode=only_full_group_by
[원인]
이 오류는 MySQL의 ONLY_FULL_GROUP_BY 모드와 관련이 있다. 이 모드가 활성화되면, SELECT 목록에 있는 모든 비집계 열은 GROUP BY 절에 포함되어야 한다.
[해결 1] 쿼리 수정
SELECT 목록에 있는 모든 비집계 열을 GROUP BY 절에 추가
[해결 2] SQL 모드 변경
1. mysql 모드 확인
select @@sql_mode;
(ONLY_FULL_GROUP_BY가 있음을 확인)
2. 아래의 SQL문 실행
SET GLOBAL sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';
SET GLOBAL sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));
SET @@sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';
https://chamch-dev.tistory.com/3
https://info-lab.tistory.com/274
반응형