0% found this document useful (0 votes)
31 views2 pages

Joins: Old/Conventional SQL New/Ansi SQL Visual Representation Result

The document describes how to create tables and insert data into them using SQL. It creates department, employee, and employee details tables. It then inserts data into the department and employee tables. It also shows how joins can be written in both the old SQL syntax using commas between tables as well as the newer ANSI SQL syntax using JOIN keywords.

Uploaded by

sumanth_0678
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views2 pages

Joins: Old/Conventional SQL New/Ansi SQL Visual Representation Result

The document describes how to create tables and insert data into them using SQL. It creates department, employee, and employee details tables. It then inserts data into the department and employee tables. It also shows how joins can be written in both the old SQL syntax using commas between tables as well as the newer ANSI SQL syntax using JOIN keywords.

Uploaded by

sumanth_0678
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Joins

CREATE TABLE dept(deptno NUMBER, dname VARCHAR2(20), loc VARCHAR2(20));

CREATE TABLE emp(empno NUMBER, manager NUMBER, deptno NUMBER, ename VARCHAR2(20), sal NUMBER);

CREATE TABLE emp_details(empno NUMBER, manager NUMBER, deptno NUMBER, ename VARCHAR2(20), sal NUMBER, effective_from DATE, effective_to DATE);

INSERT INTO DEPT (DEPTNO,DNAME,LOC) VALUES (10,'ACCOUNTING','NEW YORK');


INSERT INTO DEPT (DEPTNO,DNAME,LOC) VALUES (20,'RESEARCH','DALLAS');
INSERT INTO DEPT (DEPTNO,DNAME,LOC) VALUES (30,'SALES','CHICAGO');
INSERT INTO DEPT (DEPTNO,DNAME,LOC) VALUES (40,'OPERATIONS','BOSTON');

INSERT INTO EMP (EMPNO,MANAGER,JOB,DEPTNO,ENAME,SAL) VALUES (7369,7902,'CLERK',20,'SMITH',800);


INSERT INTO EMP (EMPNO,MANAGER,JOB,DEPTNO,ENAME,SAL) VALUES (7499,7698,'SALESMAN',30,'ALLEN',1600);
INSERT INTO EMP (EMPNO,MANAGER,JOB,DEPTNO,ENAME,SAL) VALUES (7521,7698,'SALESMAN',30,'WARD',1250);
INSERT INTO EMP (EMPNO,MANAGER,JOB,DEPTNO,ENAME,SAL) VALUES (7566,7839,'MANAGER',20,'JONES',2975);
INSERT INTO EMP (EMPNO,MANAGER,JOB,DEPTNO,ENAME,SAL) VALUES (7654,7698,'SALESMAN',30,'MARTIN',1250);
INSERT INTO EMP (EMPNO,MANAGER,JOB,DEPTNO,ENAME,SAL) VALUES (7698,7839,'MANAGER',30,'BLAKE',2850);
INSERT INTO EMP (EMPNO,MANAGER,JOB,DEPTNO,ENAME,SAL) VALUES (7782,7839,'MANAGER',10,'CLARK',2450);
INSERT INTO EMP (EMPNO,MANAGER,JOB,DEPTNO,ENAME,SAL) VALUES (7788,7566,'ANALYST',20,'SCOTT',3000);
INSERT INTO EMP (EMPNO,MANAGER,JOB,DEPTNO,ENAME,SAL) VALUES (7839,null,'PRESIDENT',10,'KING',5000);
INSERT INTO EMP (EMPNO,MANAGER,JOB,DEPTNO,ENAME,SAL) VALUES (7844,7698,'SALESMAN',30,'TURNER',1500);
INSERT INTO EMP (EMPNO,MANAGER,JOB,DEPTNO,ENAME,SAL) VALUES (7876,7788,'CLERK',20,'ADAMS',1100);
INSERT INTO EMP (EMPNO,MANAGER,JOB,DEPTNO,ENAME,SAL) VALUES (7900,7698,'CLERK',30,'JAMES',950);
INSERT INTO EMP (EMPNO,MANAGER,JOB,DEPTNO,ENAME,SAL) VALUES (7902,7566,'ANALYST',20,'FORD',3000);
INSERT INTO EMP (EMPNO,MANAGER,JOB,DEPTNO,ENAME,SAL) VALUES (7934,7782,'CLERK',10,'MILLER',1300);
INSERT INTO EMP (EMPNO,MANAGER,JOB,DEPTNO,ENAME,SAL) VALUES (7999,8000,'MANAGER',50,'MILLER',4300);
INSERT INTO EMP (EMPNO,MANAGER,JOB,DEPTNO,ENAME,SAL) VALUES (8000,7782,'MANAGER',60,'MILLER',5300);

COMMIT;

Old/Conventional SQL New/ANSI SQL Visual Representation Result

INNER JOIN

SELECT e.*, d.* SELECT e.*, d.*


FROM emp e, dept d FROM emp e
WHERE e.deptno=d.deptno; INNER JOIN dept d ON e.deptno = d.deptno;

LEFT OUTER

SELECT e.*, d.* SELECT e.*, d.*


FROM emp e, dept d FROM emp e
WHERE e.deptno = d.deptno(+); LEFT OUTER JOIN dept d ON e.deptno = d.deptno;

RIGHT OUTER

SELECT e.*, d.* SELECT e.*, d.*


FROM emp e, dept d FROM emp e
WHERE e.deptno(+) = d.deptno; RIGHT OUTER JOIN dept ON e.deptno = d.deptno;

FULL OUTER

SELECT e.*, d.* SELECT e.*, d.*


FROM emp e, dept d FROM emp e
WHERE e.deptno = d.deptno(+) FULL OUTER JOIN dept d ON e.deptno = d.deptno;
UNION ALL
SELECT e.*, d.*
FROM emp e, dept d
WHERE e.deptno(+) = d.deptno
AND e.deptno IS NULL;

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy