System/OS
2013.04.23 14:35
[sql] 조회구문(select)에서 중복 데이터를 한 번만 출력 (distinct)
조회 수 34066 댓글 1
기본적인 쿼리
select distinct * from 테이블명;
distinct * 이란건 한 행의 전체 칼럼값이 중복되는 데이터를 제거하고 뽑아냄..
예를 들어 중복된걸 제거한 제목을 뽑아 낼려면..
select distinct 제목 from 테이블명;;
전체 칼럼을 뽑아 내는데 중복된게 제목이 중복된건 하나만 출력하고 싶다면 index값이 있어야 함.
select * from 테이블명 where index in (select max(index) from 테이블명 group by 제목)
그리고 정렬은..
select * from 테이블명 where index in (select max(index) from 테이블명 group by 제목) order by 제목
만약 index값이 없다면 unique한 값으로 조건을 줘도 됨..
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
405 | Etc | [link] 유용한 사이트 링크. | hooni | 2013.08.19 | 74100 |
404 | System/OS | [linux] /etc/fstab 설정 방법.. ㅋㅋ | hooni | 2013.04.23 | 12160 |
403 | System/OS | [linux] apache, php, jsp 환경설정하기.. | hooni | 2003.04.23 | 15315 |
402 | System/OS | [linux] APM(apache, php, mysql) + gd 설치순서.. | hooni | 2003.04.23 | 18943 |
401 | System/OS | [linux] awk 명령어 | hooni | 2014.03.11 | 5044 |
400 | System/OS | [linux] CentOS 6.5 에서 "Bringing up interface eth0: Determining if ip address 121.78.127.197 is already in use for device eth0..." | hooni | 2014.04.05 | 4964 |
399 | System/OS | [linux] CentOS 6.x Cati 설치 (yum) | hooni | 2014.01.17 | 48660 |
398 | System/OS | [linux] CentOS Apache Httpd에 https 적용 | hooni | 2014.03.05 | 4592 |
397 | Develop | [linux] CentOS Apache 웹서버에 HTTPS 적용 | hooni | 2015.10.23 | 921 |
396 | System/OS | [linux] CentOS 에 APM 설치하기 | hooni | 2015.01.02 | 1912 |
395 | System/OS | [linux] CentOS 터미널 언어 설정(한글/영어) | hooni | 2013.12.22 | 18626 |
394 | Develop | [linux] crond 사용법.. ㅋㅋ | hooni | 2013.04.23 | 7277 |