having 절로 중복값 확인하기

Created by
  • 서경태
Created at
SQL에서 having절은 집계 함수(count, sum, avg, max, min 등)를 사용하여 그룹화된 데이터에 조건을 적용하는데 사용된다.
having 절은 group by 절과 함께 사용되며, where절과 비슷하지만 중요한 차이점은 아래와 같다.
where절 : 그룹화되기 전에 조건으로 필터링
having절 : 그룹화된 후에 조건으로 필터링
select id, name, host_id group by host_id having count(host_id) >= 2 order by id