본문 바로가기
Error

[MySQL] expression #1 of SELECT list contains nonaggregated column

by 지구 2020. 7. 16.

### Cause: java.sql.SQLSyntaxErrorException: In aggregated query without GROUP BY, expression #1 of SELECT list contains nonaggregated column '{{내컬럼}}'; this is incompatible with sql_mode=only_full_group_by ; bad SQL grammar []; nested exception is java.sql.SQLSyntaxErrorException: In aggregated query without GROUP BY, expression #1 of SELECT list contains nonaggregated column '{{내컬럼}}'; this is incompatible with sql_mode=only_full_group_by

 

쿼리로 데이터를 조회하던 중에 이런 에러가 났다.

찾아보니 MySQL5.7 버전 이상에서 쿼리의 안정성을 강화하기 위해서 group by 하지 않은 컬럼이 select 될 수 없다고 한다.

( 오류를 찬찬히 읽어보면 나와있다.. sql_mode=only_full_group_by )

 

이와 동시에 여타 블로그에서는 이 제약사항을 푸는 방법을 알려주지만.......

사실 저 제약사항이 걸린 컬럼들을 group by 해주면 된다.

 

 

그룹함수에 사용하고 있는 컬럼 외 select 절에 있는 다른 컬럼들을 마지막에 group by 해주니 해결 :)

반응형

댓글