Search:     Advanced search
Browse by category:
C/C++   |   Java   |   Oracle/Database   |   SAP   |   ASP .NET   |   Mainframe-DB2   |   Freshers

Q: Please explain Outer Join in SQL

Add comment
Views: 620
Votes: 3
Comments: 0
This is one of the areas that many students make a mistake and it is perhaps one of the most frequently asked question in interviews. So study it carefully.
In this type of join the query returns all rows from one table and selected number of rows from the second table.

For example say we want to find all employees from emp table and their deprtname from dept table. However the problem is some of the employees have a department id that does not exist in dept table. In such a situation we will use outer join in the SQL query.

The structure of emp table is
eno ename mgrno dept_id
Employee No Employee Name Manager Number Department id

Data in the table is
eno ename mgrno dept_id
1 suku 2 10
2 pari 3 30

The structure of dept table is
dept_id dname
Department id Departtment Name

Data in the table is
dept_id dname
10 Physics
20 Chemistry

Now run the following query

Select e.ename, d.dname
from emp e, dept d
where e.dept_id=d.dept_id(+)

This will return
ename dname
suku Physics
pari

Please see that even though pari does not have a matching record in dept the record from emp table is returned.
Others in this Category
document What is the difference between UNION and UNION ALL?
document What is Replication and Database Mirroring?
document List few advantages of Stored Procedure.
document When is the use of UPDATE_STATISTICS command?
document What are primary keys and foreign keys?
document What is RAISEERROR?
document What is a Linked Server?
document What is B-Tree?
document What are the Advantages of using CTE?
document What is DataWarehousing?
» More articles



RSS