Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the ultimate-member domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /ledcorps/www/wp/wp-includes/functions.php on line 6114 7.4 Multiple-Column Subquery – 대나무숲

7.4 Multiple-Column Subquery

출처 URL : http://www.gurubee.net/lecture/1504

Multiple-Column Subquery란?

결과 값이 두 개 이상의 컬럼을 반환하는 Subquery이다

Pairwise(쌍비교) Subquery

Subquery가 한 번 실행되면서 두 개 이상의 컬럼을 검색해서 주 쿼리로 넘겨 준다.

SELECT empno, sal, deptno
  FROM emp
 WHERE (sal, deptno) IN (SELECT sal, deptno
                          FROM emp
                         WHERE deptno = 30
                           AND comm is NOT NULL);
 
     EMPNO        SAL     DEPTNO
---------- ---------- ----------
      7521       1250         30
      7654       1250         30
      7844       1500         30
      7499       1600         30 
Nonpairwise(비쌍비교) Subquery

WHERE 절에서 두 개 이상의 서로 다른 Subquery가 사용되어서 결과 값을 주 쿼리로 넘겨 준다.

SELECT empno, sal, deptno
  FROM emp
 WHERE sal IN (SELECT sal
                 FROM emp
                WHERE deptno = 30
                  AND comm is NOT NULL);
  AND deptno IN (SELECT deptno
                   FROM emp
                  WHERE deptno = 30
                    AND comm is NOT NULL); 
 
     EMPNO        SAL     DEPTNO
---------- ---------- ----------
      7521       1250         30
      7654       1250         30
      7844       1500         30
      7499       1600         30 
Null Values in a Subquery

서브쿼리에서 NULL 값이 반환 되면 주 쿼리 에서는 어떠한 행도 반환되지 않는다.


답글 남기기 0

Your email address will not be published. Required fields are marked *