포스트

Non Equi, Cross 조인의 이해

Non Equi 조인

  • Equi 조인과 다르게 between, >, >=, < 등의 연산자를 사용하는 조인

    non equi join

Cross Join

  • Cartesian Product 조인

  • 조인 컬럼없이 두 테이블 간 가능한 모든 연결을 결합하는 조인 방식

    crossjoin

실습 문제 풀기

실습 환경에 대한 설명

실습 문제

  • 직원정보와 급여등급 정보를 추출.

    1
    2
    3
    
      select emp.*, salgrade.grade as sal_grade, salgrade.losal , salgrade.hisal 
      from hr.emp as emp
          join hr.salgrade as salgrade on emp.sal between salgrade.losal and salgrade.hisal 
    
  • 직원 급여의 이력정보를 나타내며, 해당 급여를 가졌던 시점에서의 부서번호도 함께 가져올것.

    1
    2
    3
    4
    
      select sal_hist.*, dept_hist.*
      from hr.emp_salary_hist as sal_hist
          join hr.emp_dept_hist as dept_hist on dept_hist.empno = sal_hist.empno 
              and sal_hist.fromdate between dept_hist.fromdate and dept_hist.todate 
    
  • cross 조인(예시)

    1
    2
    3
    4
    5
    6
    7
    8
    9
    
      with
      temp_01 as (
          select 1 as rnum
          union
          select 2 as rnum
      )
      select dept.*, temp_01.*
      from hr.dept
          cross join temp_01
    
이 기사는 저작권자의 CC BY 4.0 라이센스를 따릅니다.