일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 31 |
- 티스토리
- MongoDB
- oracle
- SQL
- jsp
- 오라클 디비
- 자바 프로젝트
- 학점
- K6
- JVM
- 오라클
- gradle
- 파이썬 소스
- 알고리즘
- 운영체제
- 백준 알고리즘
- resilience4j
- smart cast
- c#
- spring
- 초대장
- auto configure
- 파이썬
- 자바
- 문법 정리
- hyperledger
- 프로젝트
- 리눅스
- dynamic query
- 유사코드
- Today
- Total
모종닷컴
Oracle 문법 정리 - 서브쿼리 본문
◆서브 쿼리
메인이 아닌 쿼리 = 서브쿼리
서브 쿼리 - 1)단일 행 쿼리
2)다중 행 쿼리
1)단일 행 서브쿼리
Abel의 급여보다 많거나 같은 사원들
select last_name, salary from employees where salary >= (select salary from employees where last_name = 'Abel'); |
Taylor와 같은 직업이고 Taylor보다 높은 급여를 받는 사원
select last_name, job_id, salary from employees where job_id = (select job_id from employees where last_name = 'Taylor') and salary > (select salary from employees where last_name = 'Taylor'); |
2)다중 행 서브쿼리
any
: 서브 쿼리에서 반환되는 값 들 중 하나라도 조건을 만족한다면 띄움
select employee_id, last_name, job_id, salary from employees where salary < any (select salary from employees where job_id = 'IT_PROG') and job_id <>'IT_PROG'; |
all
: 서브 쿼리에서 반환되는 모든 값과 비교
select employee_id, last_name, job_id, salary from employees where salary < all (select salary from employees where job_id = 'IT_PROG') and job_id <>'IT_PROG'; |
exists
: 테이블에 특정 행이 있는지 여부에 따라 결과가 달라짐
SELECT * FROM departments WHERE NOT EXISTS (SELECT * FROM employees WHERE employees.department_id=departments.department_id); |
※group by 와 select문의 distinct 알아보기
'Programming > 데이터베이스' 카테고리의 다른 글
Oracle 문법 정리 - 집합 연산자 (0) | 2018.01.03 |
---|---|
Oracle 문법 정리 - join (0) | 2018.01.02 |
Oracle 문법 정리 - 그룹 함수 (0) | 2017.12.29 |
Oracle 기초 문법 정리 - 함수 사용하기 (0) | 2017.12.28 |
Oracle 문법 정리 - 데이터 제한 및 정렬 (0) | 2017.12.28 |