Professional Documents
Culture Documents
Aim: To create Employ table with the fields empno, empname, job, deptno and to create
department table with the fields deptno, deptname, location with some records inserted in each to
display the following details using joins.
i) Display empno, empname, salary, deptno, deptname, location of all the employees
ii) Display the records of the employees whose deptno in employ table is greater than
deptno in dept table.
iii) Display all the records from both the tables whose columns are in common.
iv) Display the cross product of both the tables
v) Display the all matching records and the records which are in employ table those that
are not in department table.
vi) Display the all matching records and the records which are in department table those
that are not in employ table.
vii) Display the all matching records and the non-matching records from both tables.
viii) Display all the records that have matched in both the tables using inner join.
Description: The purpose of a join is to combine the data across tables. A join is actually
performed by the where clause which combines the specified rows of tables. If a join involves in
more than two tables then oracle joins first two tables based on the joins condition and then
compares the result with the next table and so on.
EQUI JOIN: A join which contains an ‘=’ operator in the joins condition.
NON-EQUI JOIN: A join which contains an operator other than ‘=’ in the joins
condition.
NATURAL JOIN: Natural join compares all the common columns.
CROSS JOIN: This will gives the cross product.
OUTER JOIN: Outer join gives the non-matching records along with matching records.
LEFT OUTER JOIN: This will display the all matching records and the records which
are in left hand side table those that are not in right hand side table.
RIGHT OUTER JOIN: This will display the all matching records and the records which
are in right hand side table those that are not in left hand side table.
FULL OUTER JOIN: This will display the all matching records and the non-matching
records from both tables.
INNER JOIN: This will display all the records that have matched.
Queries:
Create table emp( EMPNO number(4), ENAME varchar2(25), JOB varchar2(15),
DeptNo number(2));
Insert into emp values (111, ‘saketh’,’analyst’,10);
Insert into emp values (222, ‘sudha’,’clerk’,20);
Insert into emp values (333, ‘jagan’,’manager’,10);
Insert into emp values (444, ‘madhu’,’engineer’,40);
Create table dept( DEPTNO number(2), DNAME varchar2(25), LOC varchar2(15) );
Insert into dept values (10, ‘mkt’,’hyd’);
Insert into dept values (20, ‘fin’,’bang’);
Insert into dept values (30, ‘hr’,’bombay’);
ii) select empno,ename,job,dname,loc from emp e,dept d where e.deptno > d.deptno;
EMPNO ENAME JOB DNAME LOC
---------- ---------- ---------- ---------- ----------
444 madhu engineer mkt hyd
444 madhu engineer fin bang
444 madhu engineer hr bombay