PostgreSQL / SQL Basics / 2.9 Distinct
2.9Distinct
DISTINCT keyword
SELECT
구문에 쓰여, 중복값 제거하고 unique한 값들만 뽑음
sqlSELECT DISTINCT department FROM products;
얼마나 다양한 unique 값들이 있는지 뽑을때도 유용
sqlSELECT COUNT(DISTINCT department) FROM products;
GROUP BY
와 비슷함- GROUP BY는 DISTINCT를 대체할 수 있으나, 반대로는 안됨.
DISTINCT
로 unique한 조합들만 뽑을 수도 있음
sqlSELECT DISTINCT department, name FROM products;
⇒ 단, 이렇게 하면 COUNT
같은 aggregate operator는 사용이 안됨.