JOIN

강의노트/sql 2013. 6. 14. 12:20

JOIN     >>>> 카타시안곱 " x "

같은 컬럼이 있으면 곱함....(공통점이 존재해야함)

SELECT * FROM department, employee;                >>>> 4X14    >>>공통점 dno


EQUAL JOIN    >>>> WHERE절에 " = "

SELECT * FROM department, employee WHERE employee.dno = department.dno;        >>>>중복배제(14출력)

//사원번호,사원이름,소속부서 출력

SELECT eno, ename, dname FROM employee, department 

WHERE employee.dno = department.dno and eno=7788;

//테이블과 컬럼

SELECT employee.eno, employee.ename, department.dname, department.dno 

FROM employee, department 

WHERE employee.dno=department.dno and employee.eno=7788;

//테이블 별칭

SELECT e.eno, e.ename, d.dname, d.dno 

FROM employee e, department d 

WHERE e.dno=d.dno and e.eno=7788;


NATURAL JOIN    >>>>"이름이같고, 유형이같은 컬럼끼리 조인함"

//(오류남........................)

SELECT e.eno, e.ename, d.dname, d.dno 

FROM employee e NATURAL JOIN department d

WHERE e.eno=7788;



//3개 조인

SELECT e.ename, d.dname, e.salary, s.grade 

FROM employee e, department d, salgrade s

WHERE e.dno=d.dno AND salary BETWEEN losal and hisal;


SELECT employees.ename ||'의 직속 상관은 '||manager.ename

FROM employee employees JOIN employee manager

ON employees.manager=manager.eno(+);

'강의노트 > sql' 카테고리의 다른 글

예제#4  (0) 2013.06.14
연습문제#2  (0) 2013.06.13
예제#3  (0) 2013.06.13
예제#2  (0) 2013.06.12
연습문제#1  (0) 2013.06.10