Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

SQL 'IN' Clause

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

New User


Joined: 02 Sep 2006
Posts: 31
Location: Mumbai

PostPosted: Thu Jul 30, 2009 12:55 pm    Post subject: SQL 'IN' Clause
Reply with quote

Hi,
Can anyone give me details of how IN clause operates internally

In my IN clause I have several values, some of them are repeated, will the repeated values be ignored(replaced by a single occurrence of the value) while processing the query?

Thanks,
Prasad.
Back to top
View user's profile Send private message

expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8593
Location: Back in jolly old England

PostPosted: Thu Jul 30, 2009 1:34 pm    Post subject:
Reply with quote

Would it not be better for you to try it and see what happens for yourself.
That is the best way to learn things, test and observe.
Back to top
View user's profile Send private message
prasadplease

New User


Joined: 02 Sep 2006
Posts: 31
Location: Mumbai

PostPosted: Thu Jul 30, 2009 1:41 pm    Post subject:
Reply with quote

Thanks for enlightening me, Expat
But I thought forums are where ppl who know help ppl who dont...

never mind...
Back to top
View user's profile Send private message
expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8593
Location: Back in jolly old England

PostPosted: Thu Jul 30, 2009 1:55 pm    Post subject:
Reply with quote

The forums are for helping with problems, which is not to be confused with a shortcut for you testing something yourself and seeing what the results are.

How long will it take you to perform a simple test. Probably a lot less time than you have already been waiting for the answer here.
Back to top
View user's profile Send private message
prasadplease

New User


Joined: 02 Sep 2006
Posts: 31
Location: Mumbai

PostPosted: Thu Jul 30, 2009 2:01 pm    Post subject:
Reply with quote

Hi Expat,


There is no way I can test that.
You either have to know it by virtue of having read that somewhere or being told about it by someone.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Thu Jul 30, 2009 2:02 pm    Post subject:
Reply with quote

prasadplease,
I agree with expat. You should do a little looking on your own.
actually, you are a whinny-ass who does not have the whitherwithall to
do a little research.

your attitude almost prevented me from posting the following quote from
the DB2 Developer's Guide from Craig Mullins:
Quote:

When using the IN predicate with a list of values, DB2 sorts the IN-list into ascending sequence and removes duplicates if the column specified is indexed. The IN-list values are then used to probe the index to find the matching rows. However, if there is no index for the column, DB2 will not sort the IN-list and any duplicates will remain. Upon retrieval of a row, the column value is used to search the IN-list (duplicates and all).

Therefore, it makes sense to order the elements of the IN-list, code your most restrictive predicates first, and never code duplicates in the IN-list.

Order the Elements in Your IN Lists
The order of elements in a SQL IN list can impact performance when an index is not used to process the IN list. DB2 will search the list of elements from left to right until a match is found or the end of the list is reached. For this reason, code the most commonly occurring values first in your IN lists. Doing so will cause DB2 to match as early as possible most of the time—thereby improving performance. For example, consider the following SQL statement:

SELECT EMPNO, WORKDEPT, EDLEVEL, SALARY
FROM DSN8810.EMP
WHERE WORKDEPT IN ('A00', 'A01', 'E21');

This SQL statement demonstrates the natural tendency to order lists alphabetically or numerically. The statement is correctly coded only if A00 occurs more often than A01, which occurs more often than E21. But if A01 was most common, followed by E21 and then A00, the statement would be better coded (performance-wise) as

SELECT EMPNO, WORKDEPT, EDLEVEL, SALARY
FROM DSN8810.EMP
WHERE WORKDEPT IN ('A01', 'E21', 'A00');
Back to top
View user's profile Send private message
prasadplease

New User


Joined: 02 Sep 2006
Posts: 31
Location: Mumbai

PostPosted: Thu Jul 30, 2009 2:06 pm    Post subject:
Reply with quote

Dick,
Thanks a lot for the information.
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 Need help on SQL Dynamic WHERE Clause subratarec DB2 12 Sat Jul 16, 2016 3:11 pm
No new posts [SQL0029] INTO clause missing from em... HABBIE DB2 2 Fri Sep 04, 2015 3:54 pm
No new posts 3-D Table with nested DEPENDING ON Cl... VivekKhanna COBOL Programming 5 Sat Aug 08, 2015 11:18 pm
No new posts when=group clause: question about the... tuxama DFSORT/ICETOOL 2 Thu Mar 26, 2015 12:51 pm
No new posts pic clause on group variable error CuriousMainframer COBOL Programming 6 Mon Jul 14, 2014 6:33 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us