oracle

Saturday, 22 April 2017

SQL:Left outer join

Left outer join select all the data from all columns of source table and select only required data from the target table.

Syntax:
Select columns_name from source_table left outer join target_table;

In left outer join, left table of left outer join is the source table and right side of left outer join is the target table.
It also works with both parameters, with On(expression) or with using(column_name).

Example:
select emp_name, dept_name from emp left outer join dept on(emp.emp_id = dept.emp_id);

Result:
Talha IT
Zubair Oracle
Salman Finance
shani

Waqass

To explain the working, i revert the query as.

Example:
select emp_name, dept_name from dept left outer join emp on(emp.emp_id = dept.emp_id);

Result:
Talha IT
Zubair Oracle
Salman Finance
Accounts

Marketing

We can use Left outer with different on expression to explain the working.

Example:
select emp_name, dept_name from dept left outer join emp on(emp.emp_id = dept.dept_id);

Result:
Talha IT
Zubair Oracle
Salman Finance
shani Accounts

Waqass Marketing.

Left outer join with using clause:

Example:
select emp_name, dept_name from emp left outer join dept using(emp_id);

Result:
Talha IT
Zubair Oracle
Salman Finance
shani

Waqass

No comments:

Post a Comment