기록하는 중/Spring Boot

[Spring] TooManyResultException: Expected one result(or not) to be returned by selectOne(), but found: 3

성장하는 요롱이 2024. 3. 2. 23:53

 

에러 발생
TooManyResultException: Expected one result(or not) to be returned by selectOne(), but found: 3
  • 1개의 결과만 출력되어야 하는데 3개의 결과가 찾아지는 문제가 발생
  • 보통은 list를 할텐데 list는 다른 쿼리로 뽑고 있어서 할 필요가 없었음
  • 그래서 서브 쿼리를 select max() from 을 써서 결과가 잘 나오나 봄.
  • ex ) select id, point, charge, email, phone_number from select( max(id), max(point), max(charge), max(email), max(phone_number) from user u  join payment p on  u.id = p.id)
  • 결과는 성공!