에서 연산을 보다 효율적으로 제어하기 위한 서브쿼리, 임시 테이블, 공통 테이블 표현식을 알
아봅니다.
8.3.2
서브쿼리
서브쿼리는
SQL
쿼리의 실행 순서를 제어하거나 하나의 메인 쿼리로 원하는 계산을 수행할 수
없을 때 가장 먼저 사용하는 방법입니다. 필요에 따라 긴 쿼리를 작은 단위로 구성하기 위해 사
용하기도 합니다.
산술식에서 괄호로 계산의 우선순위를 표시하듯 쿼리에서는 괄호로 서브쿼리를 구분합니다.
괄호로 감싼 서브쿼리는 외부쿼리가 실행되기 전에 독립된 하나의 쿼리로서 실행됩니다. 서브
쿼리가
FROM
절 뒤에 붙으면, 서브쿼리가 반환하는 결과 데이터셋이 마치 하나의 테이블처럼
사용됩니다. 앞서 이미 수많은 예제를 통해 서브쿼리를 활용한 코드를 살펴봤습니다.
LATERAL
서브쿼리
2
는 일반 서브쿼리와는 다른 특이한 유형으로,
JOIN
을 수행하지 않고
도 앞에 위치한
FROM
절의 테이블의 값을 가져올 수 있습니다.
JOIN
과
ON
대신 콤마(
,
)와
LATERAL
키워드를 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month, and much more.
O’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
I wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
I’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
I'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.