Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Remove Duplicate Rows from Left Outer Join

659002Sep 10 2008 — edited Sep 10 2008
Hi All,

I am new to Oracle..I have two tables as follow:

TableA(EmpID, Empname)

TableB(EmpID, DeptID, DeptName). A employee can work in multiple dept.

table A has 1 row as EmpID 1 and TableB has two rows for EmpID 1.

I have a search page which takes dept ID as parameter and return employee name...Dept ID is not mandatory feld for Search. If DeptID is passed it should return the employee who belongs to that Dept otherwise it should return 1 employee..

Now I have used as follow:

:IN_DEPTID is passed as parameter

Select EmpName from TableA Left Join tableB on a.EmpID = B.EmpID
WHERE
CASE WHEN :IN_DEPTID IS NULL
IN_DEPTID IS NULL
ELSE|
DEPTID = :IN_DEPTID

Now problem is when Dept ID is passed it correctly returns a row but if no deptid is passed it returns 2 rows but i want ony one row as there is only one employee.

Please help;

Edited by: user10239708 on 10 Sep, 2008 12:24 AM

Edited by: user10239708 on 10 Sep, 2008 12:28 AM
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 8 2008
Added on Sep 10 2008
3 comments
1,514 views