Thursday, November 26, 2009

Oracle Proprietary Joins Part I

Use a join to query data from more than one table .Rows in one table can be joined to rows in another table according common values existing in corresponding columns. That is usually primary and foreign key columns. 


select table1.column,table2.column


from table1 , table 2


where table1.column1 = table2.column2;


1)Equijoin


equijoins are aslo called simple joins or inner joins.


for example there are two tables



  1. employees with columns employee_id,first_name,last_name,department_id

  2. departments with columns department_id,department_name,location_id

retrieving records with Equijoin


select e.employee_id,e.last_name,e.department_id,d.department_id,d.location_id


from employees e,departmnets d


where e.employee_id=d.department_id



  1. The select clause specifies the columns names to retirive


  • employee last name,employee id and department id wich are columns in the Employees table

  • department id,department name and location id which are columns in departmnets table

  2. the from clause specifies the two tables that the database must access



  • employees table

  • department table

the where clause specifies how the tables are to be joined


e.department_id=d.department_id


becouse the department_id column is common to both tbales it must be prefixed by the table name to avoid ambuguity

No comments: