개발노트

[MySQL]this is incompatible with sql_mode=only_full_group_by 본문

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

 

MySQL Only Full Group By 에러 관련

문제 MySQL 관련 DB 인수인계 중 this is incompatible with sql_mode=only_full_group_by Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'XXX.I.idx' which is not functionally dependent on columns in GROUP BY cl

chamch-dev.tistory.com

 

https://info-lab.tistory.com/274

 

[MySQL] sql_mode=only_full_group_by 에러 해결 방법

여러 서비스의 MySQL을 사용하다 보면 MySQL Version(버전)을 이동하면서 사용하게 된다. 이때 5.6 Version / 5.7 Version 도 같이 사용되는 경우가 있거나, 혹은 서비스 데이터베이스(DB)가 5.6에서 5.7 Version으

info-lab.tistory.com

 

반응형