반응형
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
Tags
- VirtualBox
- Android
- ReactNative
- Chrome
- MAC
- IOS
- PYTHON
- unittest
- vsCode
- react
- localserver
- node
- picker
- androidstudio
- jest
- 개발
- centos
- 네트워크
- MachineLearning
- avds
- webpack
- 리눅스
- TensorFlow
- build
- 센토스
- xcode
- 맥
- qunit
- linux
Archives
- Today
- Total
로메오의 블로그
[SQL] distinct 중복제거 예제 본문
반응형
[ORACLE] DOCKER에 ORACLE 11G 설치하기
[POSTGRESQL] DOCKER에 POSTGRESQL 설치하기
중복된 값을 제거하는 distinct 에 대해 알아봅니다.
SQL >
SELECT COMPANY, PRODUCT
FROM (
SELECT 'Google' COMPANY, 'Android' PRODUCT FROM DUAL
UNION ALL
SELECT 'Google' COMPANY, 'Chrome' PRODUCT FROM DUAL
UNION ALL
SELECT 'Apple' COMPANY, 'Macbook' PRODUCT FROM DUAL
UNION ALL
SELECT 'Apple' COMPANY, 'iPhone' PRODUCT FROM DUAL
UNION ALL
SELECT 'Apple' COMPANY, 'iPod' PRODUCT FROM DUAL
UNION ALL
SELECT 'Samsung' COMPANY, 'Gallexy' PRODUCT FROM DUAL
)
COMPANY PRODUCT
------- -------
Google Android
Google Chrome
Apple Macbook
Apple Macbook
Apple iPhone
Apple iPod
Samsung Gallexy
7 rows selected.
위와 같은 테이블이 있습니다.
COMPANY의 중복된 값을 제거해 보겠습니다.
SQL>
SELECT DISTINCT COMPANY
FROM (
SELECT 'Google' COMPANY, 'Android' PRODUCT FROM DUAL
UNION ALL
SELECT 'Google' COMPANY, 'Chrome' PRODUCT FROM DUAL
UNION ALL
SELECT 'Apple' COMPANY, 'Macbook' PRODUCT FROM DUAL
UNION ALL
SELECT 'Apple' COMPANY, 'iPhone' PRODUCT FROM DUAL
UNION ALL
SELECT 'Apple' COMPANY, 'iPod' PRODUCT FROM DUAL
UNION ALL
SELECT 'Samsung' COMPANY, 'Gallexy' PRODUCT FROM DUAL
);
COMPANY
-------
Google
Samsung
Apple
3 rows selected.
COMPANY컬럼의 중복되는 row가 제거되고 3개의 고유한 값만 조회합니다.
이번에는 COMPANY, PRODUCT의 DISTINCT를 조회합니다.
SQL >
SELECT DISTINCT COMPANY, PRODUCT
FROM (
SELECT 'Google' COMPANY, 'Android' PRODUCT FROM DUAL
UNION ALL
SELECT 'Google' COMPANY, 'Chrome' PRODUCT FROM DUAL
UNION ALL
SELECT 'Apple' COMPANY, 'Macbook' PRODUCT FROM DUAL
UNION ALL
SELECT 'Apple' COMPANY, 'iPhone' PRODUCT FROM DUAL
UNION ALL
SELECT 'Apple' COMPANY, 'iPod' PRODUCT FROM DUAL
UNION ALL
SELECT 'Samsung' COMPANY, 'Gallexy' PRODUCT FROM DUAL
);
COMPANY PRODUCT
------- -------
Apple Macbook
Apple iPod
Apple iPhone
Samsung Gallexy
Google Android
Google Chrome
6 rows selected.
COMPANY와 PRODUCT를 모두 반영하여 중복된 row가 제거되고
고유한 값을 조회합니다.
반응형
'Backend > Oracle & SQL' 카테고리의 다른 글
[SQL] Oracle SQL Query - CASE WHEN ELSE (0) | 2019.09.02 |
---|---|
[SQLDeveloper] locale not recognized 오류 (0) | 2019.09.02 |
[Postgresql] Docker에 Postgresql 설치하기 (0) | 2019.08.26 |
[Oracle] docker에 Oracle 11g 설치하기 (0) | 2019.08.25 |
[Docker] Mac에 docker 설치하기 (0) | 2019.08.25 |
Comments