MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

SQL "Exist "

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database
View previous topic :: View next topic  
Author Message
vkphani
Intermediate


Joined: 05 Sep 2003
Posts: 483
Topics: 48

PostPosted: Tue Apr 06, 2004 2:15 am    Post subject: SQL "Exist " Reply with quote

Hi Friends,

I want the below section to be replaced with SQL "exist" for test, instead of select.
How do I do it. i.e., All I want is a True/False test against same table instead of scanning through the table and selecting a matching entry.
Code:

C2000-VALID-ACCOUNT-CHECK SECTION.
-------------------------------*
       EXEC SQL
            SELECT
                SUPP_ID
            INTO
                :WS-SUPP-ID2
            FROM
                DTWACCOUNT
            WHERE
                SUPP_ID = :WS-SUPP-ID1 AND
                ACCT_NBR = :WS-NMI-01-ACCT-NBR-RED
       END-EXEC.

C2000-EXIT.
-------------*
       EXIT.
Back to top
View user's profile Send private message Send e-mail
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12376
Topics: 75
Location: San Jose

PostPosted: Tue Apr 06, 2004 7:26 am    Post subject: Reply with quote

vkphani,

Please check this link for a detailed explanation of EXISTS predicate

http://publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/BOOKS/DSNSQH11/2.21.4?SHELF=&DT=20010718164132&CASE=

Hope this helps...

Cheers

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
nagasadhu
Beginner


Joined: 08 Jul 2006
Posts: 17
Topics: 6

PostPosted: Thu Dec 14, 2006 12:07 am    Post subject: performance differance Reply with quote

Hi

Can someone tell me if there is a diffeerence in performance between the following 2 queries?

Here index1 is a duplicate index and can have upto 25 duplicate rows.

1)
Code:

SELECT index1
      ,nonindex4
 FROM dbtst.tb1 a
     ,dbtst.tb1 b
WHERE a.nonindex1   = 'constant1'
  AND a.index1      = b.index1
  AND (b.nonindex2  = 'constant2'
   OR  b.nonindex3  = 'constant3')
       ;

2)
Code:


SELECT index1
      ,nonindex4
 from dbtst.tb1 a
WHERE a.nonindex1 = 'constant1'
  AND exists ( SELECT *
                 FROM dbtst.tb1 b
                WHERE b.index1     = a.index1
                  AND (b.nonindex2 = 'constant2'
                   OR  b.nonindex3 = 'constant3')) ;

Thanx
Back to top
View user's profile Send private message
CZerfas
Intermediate


Joined: 31 Jan 2003
Posts: 211
Topics: 8

PostPosted: Thu Dec 14, 2006 6:30 am    Post subject: Reply with quote

The difference is, that in the first case DB2 can decide, which table will be treated as outer table of the join and which one as inner table.

Your second query forces DB2 in the way the query is split into query blocks. Whether this is better or worse in terms of performance depends solely on the structure and quantity of your data.

regards
Christian
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group