Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

How to Avoid duplicates.

Hi,
I have a query. Iam selecting data from 11 tables but the problem is
The join of tables is based on different conditions.
I will give a simple example with demo tables.

select distinct empno,ename,sal,e.deptno
from emp e,salgrade,dept d
where ((e.deptno =10 and e.deptno = d.deptno)
or (e.deptno =20 and e.sal between losal and hisal))

EMPNO ENAME SAL DEPTNO
------- ---- ---- ----
7369 SMITH 800 20
7782 CLARK 2450 10
7839 KING 5000 10
7876 ADAMS 1100 20
7934 MILLER 7000 10

If distinct is not used it is fetching 14 rows.
Like this I have to join 6 tables based on conditions the problem is duplicate of Data. Distinct can be used to avoid the duplicates. But the data is very huge it is taking more than 4 minutes when the actual query is executed Is there any alternative without using distinct clause?
Or Can the same query be written in a different fashion?
I have to write the stated query in DB2.Iam new to DB2
So I write the queries first in oracle.
I really have no idea about the features in DB2 to avoid duplicates and also the availability of Rank analytical function.
The query should work in DB2. Please help me.
[1373 byte] By [Harini] at [2007-11-11 10:25:39]