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

to find intersection of rows within a table


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Singaram

New User


Joined: 19 Aug 2009
Posts: 19
Location: India

PostPosted: Mon Nov 23, 2009 4:35 am
Reply with quote

Hi,

I know that Db2 for V9 for Z/os .supports INTERSECT operation similar to UNION. But we are using Db2 V8 for Z/os, so dont have this option.

Now the question is

I have a table with two columns say name and recordno. Now I need to find the common recordno between the three different names that I supply as host variables.

Currently the query is

select recordno from X T1, X T2, X T3
where
T1.Name = :H1 and
T2.Name = :H2 and
T3.Name = :H3 and
T1.recordno = T2.Recordno
T1.recordno = T3.Recordno

I want to know is there any other better/possible way to do it in Db2 V8 for Z/OS?
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Mon Nov 23, 2009 7:26 am
Reply with quote

Why don't you provide us with some sql with proper syntax?
your
Quote:
Currently the query

will not work.

and I don't mean the lack of different table names X, X and X,
you did not qualify the recordno in the select.

so, since your accuracy is so poor, try again.

i would ask for what indexes are available,
but shudder to think what garbage you will give us then.
Back to top
View user's profile Send private message
Singaram

New User


Joined: 19 Aug 2009
Posts: 19
Location: India

PostPosted: Mon Nov 23, 2009 1:36 pm
Reply with quote

I didnt get your comments Dbz

Currently the query is : "I meant the SQL at present is:"


Please let me know what is the syntax problem in the following query, which you are trying to point out:

select T1.recordno from X T1, X T2, X T3
where
T1.Name = :H1 and
T2.Name = :H2 and
T3.Name = :H3 and
T1.recordno = T2.Recordno and
T1.recordno = T3.Recordno


Moreover the whole idea of the query is to find out the common "recordno" between the given three names in the table.

The table has two columns

Name Recordno
A 1
A 3
B 1
B 5
C 2
D 1
D 2

Input1 :- Now if the names supplied as input in the host variables are A, B & D ; then the expected output would be :

1 (Which is the only record no. that is common between these 3 names)

Input2 :- Now if the names supplied as input in the host variables are A, B & C ; then the expected output would be :

+100 (Since there is no record in common between these 3 names)

I think this time Im more clear.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Mon Nov 23, 2009 5:34 pm
Reply with quote

well, first of all you have a simple join between three tables based on two conditions.

second, your select statement in your second post is different than that of the first.

third, I would not have used a UNION at all, thus I think you have miss-read the use of the db2 vsn 9 INTERCEPT clause.

review your examine output and determine what, if any, changes need to be made with indexes.

and yes, the second time you showed the respect due to members of this board by posting a clear and concise question.
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 Load new table with Old unload - DB2 DB2 6
No new posts To get the count of rows for every 1 ... DB2 3
No new posts Pulling a fixed number of records fro... DB2 2
No new posts To find whether record count are true... DFSORT/ICETOOL 6
No new posts Multiple table unload using INZUTILB DB2 2
Search our Forums:

Back to Top