0% found this document useful (0 votes)
48 views5 pages

Equi Join-3

Equi join extracts information from multiple tables by comparing common columns that are equal. It performs an inner join to display matching column values. Non-equi joins extract information without comparing columns equal, instead using operators like BETWEEN. Outer joins return all rows from the first table and matching rows from the second table, returning nulls if no match exists.

Uploaded by

Harik C
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)
48 views5 pages

Equi Join-3

Equi join extracts information from multiple tables by comparing common columns that are equal. It performs an inner join to display matching column values. Non-equi joins extract information without comparing columns equal, instead using operators like BETWEEN. Outer joins return all rows from the first table and matching rows from the second table, returning nulls if no match exists.

Uploaded by

Harik C
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/ 5

Equi join

Extracting the information from more than one table by comparing ( = ) the
common information.
Note : Equi Joins are also called as simple joins or Inner Joins
To display common column information
INPUT:
SQL> SELECT empno,ename,job,sal,dname FROM emp,dept WHERE emp.deptno = dept.deptno
OUTPUT:
EMPNO ENAME JOB SAL DNAME
---------- ---------- --------- ---------- --------------
7782 CLARK MANAGER 2450 ACCOUNTING
7839 KING PRESIDENT 5000 ACCOUNTING
7934 MILLER CLERK 1300 ACCOUNTING
7369 SMITH CLERK 800 RESEARCH
7876 ADAMS CLERK 1100 RESEARCH
7902 FORD ANALYST 3000 RESEARCH
7788 SCOTT ANALYST 3000 RESEARCH
7566 JONES MANAGER 2975 RESEARCH
7499 ALLEN SALESMAN 1600 SALES
7698 BLAKE MANAGER 2850 SALES
7654 MARTIN SALESMAN 1250 SALES
7900 JAMES CLERK 950 SALES
7844 TURNER SALESMAN 1500 SALES
7521 WARD SALESMAN 1250 SALES
ANALYSIS:
Efficiency is more when we compare the information from lower data table(master table)
to Higher data table( child table).
When Oracle processes multiple tables, it uses an internal sort/merge procedure to
join those tables. First, it scans & sorts the first table (the one specified last in
FROM clause). Next, it scans the second table (the one prior to the last in the FROM
clause) and merges all of the retrieved from the second table with those retrieved
from the first table. It takes around 0.96 seconds
INPUT:
SQL> SELECT empno,ename,job,sal,dname FROM emp,dept WHERE emp.deptno = dept.deptno;
ANALYSIS:
Here driving table is EMP. It takes around 26.09 seconds
Technology Learning Services - MSLW Oracle SQL
So, Efficiency is less.
Workbook - Page No : 131
Non-Equi joins
Getting the information from more than one table without using comparison (=)
operator.
INPUT:
SQL> SELECT empno,ename,sal,grade,losal,hisal FROM salgrade g,emp e
WHERE e.sal BETWEEN g.losal and g.hisal;
ANALYSIS:
Displays all the employees whose salary lies between any pair of low and high salary
ranges.
INPUT:
SQL> SELECT * FROM dept WHERE deptno NOT IN (SELECT DISTINCT deptno FROM emp);
OUTPUT:
DEPTNO DNAME LOC
---------- -------------- -------------
40 OPERATIONS BOSTON
ANALYSIS:
Displays the details of the department where there are no employees
We can also get above output using relational algebra operators.
SQL> SELECT deptno FROM dept MINUS SELECT deptno FROM emp;
SQL> SELECT deptno FROM dept UNION SELECT deptno FROM emp;
SQL> SELECT deptno FROM dept UNION ALL SELECT deptno FROM emp; Technology Learning
Services - MSLW Oracle SQL Workbook - Page No : 132
OUTER JOIN
It is a join, which forcibly joins multiple tables even without having the common
information. It is represented by +.
INPUT:
SQL> SELECT empno,ename,job,sal,dname FROM dept,emp WHERE dept.deptno = emp.deptno(+);
OUTPUT:
EMPNO ENAME JOB SAL DNAME
---------- ---------- --------- ---------- --------------
7782 CLARK MANAGER 2450 ACCOUNTING
7839 KING PRESIDENT 5000 ACCOUNTING
7934 MILLER CLERK 1300 ACCOUNTING
7369 SMITH CLERK 800 RESEARCH
7876 ADAMS CLERK 1100 RESEARCH
7902 FORD ANALYST 3000 RESEARCH
7788 SCOTT ANALYST 3000 RESEARCH
7566 JONES MANAGER 2975 RESEARCH
7499 ALLEN SALESMAN 1600 SALES
7698 BLAKE MANAGER 2850 SALES
7654 MARTIN SALESMAN 1250 SALES
7900 JAMES CLERK 950 SALES
7844 TURNER SALESMAN 1500 SALES
7521 WARD SALESMAN 1250 SALES
OPERATIONS Technology Learning Services - MSLW Oracle SQL Workbook - Page No
: 133
LEFT, RIGHT AND FULL OUTER JOIN
As of Oracle 9i, you can use the ANSI SQL standard syntax for outer joins. In the
FROM clause, you can tell Oracle to perform a LEFT, RIGHT or FULL OUTER join.
INPUT:
SQL> SELECT empno, ename, job, dept.deptno, dname FROM emp
LEFT OUTER JOIN dept ON dept.deptno = emp.deptno;
OUTPUT:
EMPNO ENAME JOB DEPTNO DNAME
---------- ---------- --------- ---------- --------------
7934 MILLER CLERK 10 ACCOUNTING
7839 KING PRESIDENT 10 ACCOUNTING
7782 CLARK MANAGER 10 ACCOUNTING
7902 FORD ANALYST 20 RESEARCH
7876 ADAMS CLERK 20 RESEARCH
7788 SCOTT ANALYST 20 RESEARCH
7566 JONES MANAGER 20 RESEARCH
7369 SMITH CLERK 20 RESEARCH
7900 JAMES CLERK 30 SALES
7844 TURNER SALESMAN 30 SALES
7698 BLAKE MANAGER 30 SALES
7654 MARTIN SALESMAN 30 SALES
7521 WARD SALESMAN 30 SALES
7499 ALLEN SALESMAN 30 SALES
ANALYSIS:
Gets the common information, and forcibly joins from left side table to right side
table.
INPUT:
SQL> SELECT empno, ename, job, dept.deptno, dname FROM dept
LEFT OUTER JOIN emp ON dept.deptno = emp.deptno;
OUTPUT:
EMPNO ENAME JOB DEPTNO DNAME
---------- ---------- --------- ---------- --------------
7369 SMITH CLERK 20 RESEARCH
7499 ALLEN SALESMAN 30 SALES
7521 WARD SALESMAN 30 SALES
7566 JONES MANAGER 20 RESEARCH
7654 MARTIN SALESMAN 30 SALES
7698 BLAKE MANAGER 30 SALES
7782 CLARK MANAGER 10 ACCOUNTING
7788 SCOTT ANALYST 20 RESEARCH
7839 KING PRESIDENT 10 ACCOUNTING
7844 TURNER SALESMAN 30 SALES
7876 ADAMS CLERK 20 RESEARCH
7900 JAMES CLERK 30 SALES
7902 FORD ANALYST 20 RESEARCH
7934 MILLER CLERK 10 ACCOUNTING
40 OPERATIONS
ANALYSIS:
Gets the common information from both tables, then forcibly joins from dept table to
emp table. Technology Learning Services - MSLW Oracle SQL Workbook - Page No
: 134
INPUT:
SQL> SELECT empno, ename, job, dept.deptno, dname FROM dept
RIGHT OUTER JOIN emp ON dept.deptno = emp.deptno;
OUTPUT:
EMPNO ENAME JOB DEPTNO DNAME
---------- ---------- --------- ---------- --------------
7369 SMITH CLERK 20 RESEARCH
7499 ALLEN SALESMAN 30 SALES
7521 WARD SALESMAN 30 SALES
7566 JONES MANAGER 20 RESEARCH
7654 MARTIN SALESMAN 30 SALES
7698 BLAKE MANAGER 30 SALES
7782 CLARK MANAGER 10 ACCOUNTING
7788 SCOTT ANALYST 20 RESEARCH
7839 KING PRESIDENT 10 ACCOUNTING
7844 TURNER SALESMAN 30 SALES
7876 ADAMS CLERK 20 RESEARCH
7900 JAMES CLERK 30 SALES
7902 FORD ANALYST 20 RESEARCH
7934 MILLER CLERK 10 ACCOUNTING
ANALYSIS:
Gets the common information from both tables, and then forcibly joins from dept table
to emp table.
INPUT:
SQL> SELECT empno, ename, job, dept.deptno, dname FROM emp
RIGHT OUTER JOIN dept ON dept.deptno.deptno = emp.deptno;
OUTPUT:
EMPNO ENAME JOB DEPTNO DNAME
---------- ---------- --------- ---------- --------------
7369 SMITH CLERK 20 RESEARCH
7499 ALLEN SALESMAN 30 SALES
7521 WARD SALESMAN 30 SALES
7566 JONES MANAGER 20 RESEARCH
7654 MARTIN SALESMAN 30 SALES
7698 BLAKE MANAGER 30 SALES
7782 CLARK MANAGER 10 ACCOUNTING
7788 SCOTT ANALYST 20 RESEARCH
7839 KING PRESIDENT 10 ACCOUNTING
7844 TURNER SALESMAN 30 SALES
7876 ADAMS CLERK 20 RESEARCH
7900 JAMES CLERK 30 SALES
7902 FORD ANALYST 20 RESEARCH
7934 MILLER CLERK 10 ACCOUNTING
40 OPERATIONS
ANALYSIS:
Gets the common information from both tables, then forcibly joins from dept table to
emp table.

You might also like