Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
How to optimize aN sql query which is having a join

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
View previous topic :: :: View next topic  
Author Message
Minu Mary Raju

New User


Joined: 20 Nov 2007
Posts: 5
Location: Chennai

PostPosted: Thu Nov 22, 2007 4:22 pm    Post subject: How to optimize aN sql query which is having a join
Reply with quote

hi,

i am having an SQL query which in turn to be used as an Unload card in BMC Unload utility. Currently mu query is taking long time to execute and it is not giving me an output. I have used an order by clause in the same and i believe it is causing the problem. Because when i try executing the same with out the order by cluase it get executed fast. Can anyone suggest me some other way to implement this query and to optimise it.

the query is as follows: i want to extract 3 fields from 2 tables when mortgage value in both tables are same and also for the maximum value of application sequence.

UNLOAD DIRECT NO
SELECT M1.MORTGAGE
,N1.APPROPVAL
,N1.DATE
FROM TABLE1 M1
,TABLE2 N1
WHERE N1.APPLSEQ=(SELECT MAX(N2.APPLSEQ) FROM TABLE2 N2
WHERE N2.MORTGAGE=M1.MORTGAGE)
ORDER BY MORTGAGE
WITH UR;

Any pointers to the same will be appreciated.

Regards
Minu.
Back to top
View user's profile Send private message

stodolas

Active Member


Joined: 13 Jun 2007
Posts: 632
Location: Wisconsin

PostPosted: Thu Nov 22, 2007 6:29 pm    Post subject:
Reply with quote

Have you attempted to use the DB2 function EXPLAIN? Look it up in the manual and see what that gets you. Also are you doing an order by M1.Mortgage or N1.Mortgage.

Your syntax looks a little funny, try this and see if you there is any improvment:
Code:
SELECT M1.MORTGAGE
,N1.APPROVAL
,N1.DATE
FROM TABLE1 M1,TABLE2 N1
WHERE N1.MORTGAGE=M1.MORTGAGE
AND N1.APPLSEQ = (SELECT MAX(N2.APPLSEQ) FROM TABLE2 N2)
ORDER BY M1.MORTGAGE
WITH UR;
Back to top
View user's profile Send private message
stodolas

Active Member


Joined: 13 Jun 2007
Posts: 632
Location: Wisconsin

PostPosted: Thu Nov 22, 2007 6:30 pm    Post subject:
Reply with quote

Correction:
Code:

SELECT M1.MORTGAGE
,N1.APPROVAL
,N1.DATE
FROM TABLE1 M1,TABLE2 N1
WHERE N1.MORTGAGE=M1.MORTGAGE
AND N1.APPLSEQ = (SELECT MAX(N2.APPLSEQ) FROM TABLE2 N2)
ORDER BY M1.MORTGAGE
FOR READ ONLY
WITH UR;
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts HEX value search in a DB2 query maxsubrat DB2 2 Wed Oct 04, 2017 3:04 pm
No new posts Create procedure issues -628 when add... chandraBE DB2 1 Mon Sep 18, 2017 12:16 pm
No new posts Join records from 2 files with No Dup... Poha Eater DFSORT/ICETOOL 22 Sun Aug 27, 2017 10:35 pm
No new posts Can we limit length in concatenation ... balaji81_k DB2 7 Tue Aug 22, 2017 2:50 am
No new posts Optimize sort inrec parse vishwakotin DFSORT/ICETOOL 6 Mon Jun 26, 2017 11:15 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us