최대급여가 35000이상 40000이하인 사람의 성과 이름을 검색할때
select first_name, last_name
from employees
inner join jobs
on employees.job_id = jobs.job_id
where jobs.max_salary >= 35000
--
select employees.first_name, employees.last_name
from employees
where job_id=(select job_id from jobs where max_salary >= 35000 and max_salary <=40000)
두가지 쿼리문을 전송하면 똑같은 결과가 나오는데
innerjoin문을 사용하는것이 어떤면에서 편리한가요?
개인적으론 그냥 괄호치고 조건을 입력하는게 더 편해보여서 -ㅅ-;;
데이터 건수가 많아질 때 차이가 많이 납니다.
데이터가 적으면 인덱스 설정도 필요없고 이너조인하고 서브쿼리 차이도 없어요.
bard님 말씀대로 실행 계획을 살펴보시면 어떻게 수행되는지 Step 별로 아실 수 있을 거에요.
레코드셋의 개수가 적을 때는 설령 계획이 다르더라도 별 차이 없지만,
검색 대상이 많을 경우 수백배의 차이를 낼 수도 잇습니다.
서브쿼리의 경우 저렇게 검색된 결과값이 적으면 유용하게 쓰일 수 있지만 그 대상 자체가 많아버리면 성능에 문제를 줄 뿐만 아니라,
서브쿼리로 나온 검색 결과와의 조인시 한 컬럼밖에 할 수가 없지요.
(아예 안되는건 아닙니다. 하지만 이너 조인의 경우엔 A INNER JOIN B ON A.xx = B.xx AND A.yy = B.yy 처럼 좀 더 명시적으로 구분되게 작성할 수 있습니다)
오라클의 경우엔 교육과정 중에 퍼포먼스 튜닝이 들어가 있으니 관련 서적이나 독학하시는 것도 많은 도움이 되실 거에요. 저도 아직 헤매는 중...ㅎㅎ
그나저나 본문 폰트에 댓글과 리스트까지 전부 영향을 받는 버그가 있었군요..ㅋ 닫기가 안되었나봐요.
explain 으로 execution plan을 살펴보세요. 요새 쿼리 옵티마이져들이 워낙 좋아서... 간단한 쿼리는 별 차이 안납니다.