optimize sql statement

Hello,

How can I optimize this query :
select DAA.ZORIDOS_0,'DAA-', DAA.CPY_0, sum(DAA.AMTCUR_0*DAE.SNS_0)
from ODS1.GACCENTRYA DAA,
     ODS1.GACCENTRYD DAE,
     ODS1.GACCENTRY  HAE
where DAE.ZORIDOS_0=DAA.ZORIDOS_0
and   DAE.TYP_0=DAA.TYP_0
and   DAE.NUM_0=DAA.NUM_0
and   DAE.LIG_0=DAA.LIG_0
and   DAE.SNS_0=-1
and   HAE.ZORIDOS_0=DAE.ZORIDOS_0
and   HAE.TYP_0=DAA.TYP_0
and   HAE.NUM_0=DAA.NUM_0
group by DAA.ZORIDOS_0,DAA.CPY_0

The cost of join between GACCENTRYA et GACCENTRYD is very high.

Thanks

Regards

bibi
bibi92Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Patrick MatthewsCommented:
You can try rewriting as:


select DAA.ZORIDOS_0,'DAA-', DAA.CPY_0, sum(DAA.AMTCUR_0*DAE.SNS_0) 
from ODS1.GACCENTRYA DAA INNER JOIN 
     ODS1.GACCENTRYD DAE ON DAE.ZORIDOS_0=DAA.ZORIDOS_0 and 
          DAE.TYP_0=DAA.TYP_0 and DAE.NUM_0=DAA.NUM_0 and DAE.LIG_0=DAA.LIG_0 INNER JOIN
     ODS1.GACCENTRY  HAE ON HAE.ZORIDOS_0=DAE.ZORIDOS_0 and HAE.TYP_0=DAA.TYP_0 and
          and   HAE.NUM_0=DAA.NUM_0
where  DAE.SNS_0=-1 
group by DAA.ZORIDOS_0,DAA.CPY_0

Open in new window


In any event, you should make sure that all of your tables have proper indexes set up to facilitate the join.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
bibi92Author Commented:
Thanks bibi
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.