How To Use Joins In Oracle
Description
Joins are used to retrieve the data from the multiple tables in Oracle.
- Inner join
- Outer join
- Left-Outer-Join
- Right-Outer-Join
- Full-Outer-Join
Inner join is a keyword in Oracle. Joins are used to combine the data from the tables.
Visual Illustration
Syntax
- Select columns
- from table 1
- inner join table 2
- on table 1.column = table 2.column;
Example
In the example, given below, there are two tables. Employee is the first table and Order1 is the second table.
- select Employee.emp_id,employee.emp_name
- from employee
- inner join order1
- on employee.emp_id = order1.order_id;
Left Outer Join
Left outer join returns all the rows from the left hand table. Outer join joins table A, table B and returns all the rows from table A and is called Left Outer Join in Oracle.
Visual Illustration
Syntax
- Select columns
- from table 1
- Left Outer join table 2
- ON table 1.column = table 2.column;
Example
- Select Emp_id, Emp_name
- from Employee
- Left Outer Join order1
- ON Employee.emp_id = Order1.Order_id
Right Outer Join
Right Outer Join returns all the rows from the right hand table.
Syntax
- Select columns
- from table 1
- Right outer join table 2
- on table 1.column = table 2.column;
Example
- Select Emp_id, Emp_name, Emp_job
- from Employee
- Right Outer Join order1
- ON Employee.emp_id = Order1.Order_id;
Full Outer Join
Full Outer Join returns all the rows from the left hand table and right hand with null value.
Syntax
- Select columns
- from table 1
- Full outer join table 2
- on table 1.column = table 2.column;
Example
- Select Emp_id, Emp_name, Emp_job
- from Employee
- Full Outer Join order1
- ON Employee.emp_id = Order1.Order_id;
Summary