IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

SQL 'IN' Clause


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
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
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: 8797
Location: Welsh Wales

PostPosted: Thu Jul 30, 2009 1:34 pm
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
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: 8797
Location: Welsh Wales

PostPosted: Thu Jul 30, 2009 1:55 pm
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
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
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
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts To search DB2 table based on Conditio... DB2 1
No new posts NOT IN clause in COBOL pgm COBOL Programming 8
No new posts SUSBSCRIPT WITH SIGN IN PIC CLAUSE COBOL Programming 3
No new posts usage of CASE in WHERE clause DB2 10
No new posts Cobol redefines for Signed pictured c... COBOL Programming 4
Search our Forums:

Back to Top