오늘은 SQL 활용에 대해 공부하고 연습 문제를 푸는 시간을 가졌습니다 !
그리고 SQLD의 꽃 조인을 집중적으로 학습하였습니다 :)
<공부 내용>
조인 (R-DB의 이유)
조인의 종류
ex)
cross 조인 :
select from student cross join enrol;
equi 조인 :
1) select from student, enrol
where student.stu_no = enrol.stu_no;
2) select from student natural join enrol natural join subject;
3) select from student join enrol using(stu_no) join enrol using(sub_no);
4) select * from student join enrol on student.stu_no = enrol.stu_no
join subject on student.stu_no = subject.stu_no;
Non-equi 조인 : select empno, ename, sal, grade
from emp, salgrade
where sal between losal and hisal; 예시가 이것 뿐,, 실무 X
Self 조인 :select a.empno as 사원번호, a.ename as 사원이름,
b.empno as 상급자사원번호, b.ename as 상급자이름
from emp a, emp b
where a.mgr = b.empno; (no 공통 칼럼, king 은 없겠쥬)
outer 조인 : select a., b.sub_no, sub_name
from enrol a right outer join subject b
on a.sub_no = b.sub_no
order by 1; + where a.sub_no is null; and > or
SELECT a.empno AS 사원번호, a.ename AS 사원이름,
b.empno AS 상급자사원번호, b.ename AS 상급자이름
FROM emp a
LEFT OUTER JOIN emp b ON a.mgr = b.empno
WHERE a.mgr IS NULL OR b.empno IS NULL;