괴발개발
exists 정리! 본문
1.
[ exist의 중요한 점!!!!]
0과 1을 반환하는거긴 함.
but , 테이블이 달라진다면
조건(where)으로 들어갈 때 걸러서 들어간다!
2. 테이블이 다르지 않을 때
select ename, job, deptno from emp
where exists(select deptno from dept where loc = 'LA' or loc = 'boston');
이렇게 하면 'la' ' boston'에 해당하는 인덱스 번호인 2,4 만 걸러서 보여주지 않고. 그냥 emp의 내용들 전부 다 보여준다.
3. 테이블이 달라질 때
select ename, job, deptno from emp e
where exists(select deptno from dept d where e.deptno = d.deptno);
테이블이 다르고 연관되는 거라면
이렇게 1,2,4 에 해당하는 정보만 걸러서 보여줌.
why? 하나씩 컬럼들을 따지면서 보여주니까
4. dept에서 emp와인덱스가 겹치고(and) loc = 'la', loc='boston' 인 것 만 보여주고 싶을 때
select ename, job, deptno from emp e
where exists(select deptno from dept d where e.deptno = d.deptno and (loc = 'LA' or loc = 'boston'));
'BACK END > SPRING' 카테고리의 다른 글
context경로 무시한다는게 무슨말임. + 생성자 해준 이유(dao에서) (0) | 2023.03.26 |
---|---|
BoardModel 순서 정리 (0) | 2023.03.26 |
질문 (0) | 2023.03.21 |
[강의 정리]TRANSACTION (0) | 2023.03.20 |
Shallow Copy (0) | 2023.03.19 |
Comments