In a database where the tables are
normalized, one table may not give you all information about a particular
entity. So for comprehensive data analysis, you must assemble data from several
tables.
Different types of joins
·
Inner join
·
Outer join
·
Natural join
Inner join
Inner join returns the matching rows form the tables that
are being joined.
Consider the following relations
- Employee(emp_name, city)
- Employee_salary(emp_name, department, salary)
SQL> select
employee.emp_name,employee_salary.salary from employee inner
join
employee_salary
on
employee.emp_name=employee_salary.emp_name;
SQL> select * from employee inner
join employee_salary
on
employee.emp_name=employee_salary.emp_name;
·
Left outer
·
Right outer
·
Full outer
Left outer join
The left outer join returns matching rows from the table
being joined, and also matching rows from the left table in the result and
places null values in the attributes that comes from the right table.
Example 1:
select employee.emp_name,salary from employee left
outer join employee_salary
on
employee.emp_name=employee_salary.emp_name;
Shows the following result
Right outer join
The right outer join operation returns matching rows from
the tables being joined and also non-matching rows from the right table in the
result and places null values in the attributes that comes from the left table.
Example 1:
SQL> select employee.emp_name,salary from employee right outer join
employee_salary
on
employee.emp_name=employee_salary.emp_name;
Shows following result
0 comments:
Post a Comment