Thursday, April 21, 2011

Learn "Joins" with Examples(Answers)

create table contact_details02(code_no varchar(30) references emp_master02(emp_no),phone_no number(10),address varchar(30))

emp_master02

branch_master02


1)List the employee details along with branch names to which they belong..

   select * from emp_master02 e inner join branch_master02 b on e.branchno=b.branchno

2)List the employee details of only those employees who belong to the Administration department along with branch names to which they belong.

  select * from emp_master02 e inner join branch_master02 b on e.branchno=b.branchno where e.dept='software'

3)List the employee details along with the contact details using Right outer join.

  select * from contact_details02 c right outer join emp_master02 e on e.emp_no= c.code_no

4)List the employee details along with the contact details using Left outer join.

  select * from contact_details02 c left outer join emp_master02 e on e.emp_no= c.code_no