728x90

    JOIN(조인)에 대한 이해 - 2



    조인

    non equal join

    테이블(뷰, 인라인뷰)과 테이블(뷰, 인라인뷰) 사이에 join 찍어서 조인.

    1). inner join : 내부조인


    ex)

    select *

    from employees e inner join departments d 

    on e.department_id = d.department_id; -- 조인 조건절.

    --킴벌리는 안보임

    -- inner 는 생략가능하다.


    select *

    from employees e join departments d 

    on e.department_id = d.department_id;


    조인

    2). outer join : 외부조인


    select *

    from employees e left outer join departments d 

    on e.department_id = d.department_id;

    --왼쪽에 있는 모든테이블을 먼저 보이고 매핑시켜라


    select *

    from employees e right outer join departments d 

    on e.department_id = d.department_id;

    --오른쪽에 있는 모든테이블을 먼저 보이고 매핑시켜라


    select *

    from employees e full outer join departments d 

    on e.department_id = d.department_id;

    --양쪽 모두 보이고 매핑시켜라 


    조인

    select *

    from employees e full join departments d 

    on e.department_id = d.department_id;

    -- outer도 생략가능하다~!!!!


     (left outer join, right outer join, full outer join)

     

     select *

      from employees e join departments d 

      on e.department_id = d.department_id; --이너 조인

     

     select *

      from employees e full join departments d 

      on e.department_id = d.department_id; -- 아웃터조인


    왜 굳이 테이블을 나눠서 데이터를 가져오기 위해서는 조인을 사용해야 될까?

    조인

    DB에서 테이블을 나누는 이유.


     방대한 데이터에서의 중복된 데이터를 제거해줌으로써 데이터의 사이즈를 줄인다면 디스크에 저장되는 데이터의 양이 적어지므로 메모리를 적게 쓸수 있음, (DB성능의 향상)


    럭키

    '공감'버튼 및 '좋아요'는 글쓴이에게 큰 힘이 됩니다!


    Posted by 천상나타