Labels

2017 absence absence management Account accounting AIM aliases AME and API application application utilities lookups approval assignments ATO Australia Bank bi publisher budget business business groups CAGR candidates cartisian product case CEMLI Center Stage channels Classification competency concurrent Configuration configuration profile constants contextualization conversion correction cost costing coverage area customization data database date DateTracked deductions define design develop DFF diagnostics document earnings ebs EIT Element employee enhancements erp excel expression extension failure Fastformula FBT Flexfield FND fndload foreign key forms Formula fringe benefit FRM-40654 from FTE Functions fund fusion GL global transfer grade help hierarchy HR HRMS human resource management system implementation income information interfaces internet interview job join key flexfield KFF KPI language learning leave legal employer legislation links lists localization location management New Year obia obiee OLF onboarding oracle oracle applications oracle descriptive flex field oracle descriptive flexfield oracle ebs oracle erp oracle fusion HCM oracle hrms oracle hrms interview questions oracle hrms modules oracle hrms modules list oracle hrms organization oracle hrms table oracle hrms tables oracle hrms tutorial oracle irecruitment oracle legal entities oracle lookups oracle organization hierarchy oracle payroll oracle payroll interview questions oracle payroll tables oracle self service order by Organization organization type otbi package package body package specification patch payg Payment payroll people group perform person personalisation phase pl/sql position primary key process profile programs project qualifier Query question questions Recruiting Center Recruitment regex regular expression reporting tool reports requests requirement requisition resume retropay RICE salary schema security profile select SIT smartorg sql statutory stores STP Super Superannuation system systems Table Taleo taleo 15B Taleo Recruitment tax termination test testing trunc update user group user management user type value set variables View Views Web ADI webadi where work relationship

Tuesday, 16 December 2014

Table Joins in SQL – Part III


Moving on, let us see the different types of Oracle joins - 
  • Oracle INNER JOIN (or sometimes called simple join)
  • Oracle LEFT OUTER JOIN (or sometimes called LEFT JOIN)
  • Oracle RIGHT OUTER JOIN (or sometimes called RIGHT JOIN)
  • Oracle FULL OUTER JOIN (or sometimes called FULL JOIN)


So let's discuss Oracle JOIN syntax, look at visual illustrations of Oracle JOINS, and explore them with help of examples.

INNER JOIN (SIMPLE JOIN)

Chances are, you've already written a statement that uses an Oracle INNER JOIN. It is the most common type of join. Oracle INNER JOINS return all rows from multiple tables where the join condition is met.

select *
from   per_all_people_f papf,
          per_all_assignments_f paaf
where papf.person_id = paaf.person_id

This Oracle INNER JOIN example would return all rows from the people and assignment tables where there is a matching person_id value in both the people and assignment tables.

OUTER JOINS

Outer joins extend the capacity of Oracle queries to include handling of situations where you want to see information from tables even when no corresponding records exist in the common column.  The purpose of an outer join is to include non-matching rows, and the outer join returns these missing columns as NULL values. A (+) operator is required either on left or right side of the join condition depending on “NULL” values to be fetched from which table.


LEFT OUTER JOIN (or simply LEFT JOIN)


This type of join returns all rows from the LEFT-hand table specified in the condition and only those rows from the other table where the joined fields are equal (join condition is met).

select 
paaf.assignment_number,
paaf.job_id "assg_job_id",
paaf.person_id,
pj.job_id,
pj.name "designation"
from  per_jobs pj,
        per_all_assignments_f paaf
where pj.job_id = paaf.job_id(+)
order by paaf.assignment_number

The above query will return all rows of assignment table and only those rows of per_jobs table where the join condition is met


RIGHT OUTER JOIN (or simply RIGHT JOIN)

This type of join returns all rows from the RIGHT-hand table specified in the condition and only those rows from the other table where the joined fields are equal (join condition is met).
select 
paaf.assignment_number,
paaf.location_id “assg_location_id”,
paaf.person_id,
hla.location_id,
hla.location_code “Location Name”
from  per_all_assignments_f paaf,
        hr_locations_all hla
where paaf.location_id = hla.location_id (+)
order by paaf.assignment_number

The above query will return all rows of location table and only those rows of assignment table where the join condition is met


FULL OUTER JOIN (or simply FULL JOIN)

This type of join returns all rows from the LEFT-hand table and RIGHT-hand table with nulls in place where the join condition is not met.The FULL OUTER JOIN example can only be written using a UNION query
.
select location_id from per_all_assignments_f
UNION
select location_id from hr_locations_all

The above query will return all records of both the tables 


No comments:

Post a Comment