* order by
- order by 칼럼 (asc 생략가능) : 조회된 행(레코드 row)을 기준에 맞도록 정렬(sort)
- order by 칼럼 desc => 데이터가 큰 값부터 정렬
- order by 구문은 select 구문의 마지막에 작성.
ex) 1학년 학생의 이름, 키를 출력 . 키 가 작 은 순 으로.. -> 오름차순정렬
select name, height from student where grade = 1 order by height; // order by height asc; 가능
- 컬럼 순서번호로 조회
ex) 컬럼의 순서 name, height 이기때문에 order by 2는 height의 정렬이다.
select name, height from student where grade = 1 order by 2;
- alias로 설정된 것으로도 order by 명령어로 기입해서 사용할 수 있다.
select name 이름, height 키 from student where grade = 1 order by 키; //'키' 별명 기준으로 조회
ex) 1학년 학생의 이름, 키를 출력 . 키 가 큰 순으로.. -> 내림차순정렬
select name, height from student where grade = 1 order by height desc;
- 집합 연산자 Union
-- union : 합집합. 정렬됨. 중복안됨
-- union all : 합집합. 정렬되지 않음. 두개의 결과를 합하여 출력 중복결과 조회됨
* union 을 사용할때 두개의 조회되는 컬럼의 갯수가 같아야함 .
ex) 학생중 101학과 학생의 학번,이름 학과번호, 101학과의 교수의 교수번호, 이름, 학과번호
select studno, name, deptno1 from student where deptno1 = 101 union
select profno, name, deptno from professor where deptno = 101;
ex) 위의 결과값을 조회되는 순서 그대로 쌓여서 보여준다.
select studno, name, deptno1 from student where deptno1 = 101 union all
select profno, name, deptno from professor where deptno = 101;
'Oracle SQL' 카테고리의 다른 글
Oracle SQL #6 Join (4) | 2022.03.20 |
---|---|
Oracle SQL #5 그룹함수(group by), sum, avg, max, min, having (0) | 2022.03.19 |
Oracle SQL #4 문자 관련 함수,수 관련 함수, 날짜함수, 형변환 함수, 기타 함수 (0) | 2022.03.19 |
Oracle SQL #2 desc, distinct, between, like, in, not like, not in, is null, in not null (0) | 2022.03.19 |
Oracle SQL #1 설치 및 기본 조회(Select, where), 임시컬럼, 별명주기, 기본 연산자 (0) | 2022.03.19 |