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

Retrieve data from 10 tables in QMF


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

New User


Joined: 17 Sep 2007
Posts: 17
Location: Pune

PostPosted: Tue Sep 08, 2009 12:22 pm
Reply with quote

Hi All,

I want to retrieve data from 7 different tables. There is no condition we have to retrieve all the tables data.
It might be like that the user1 is in table1 but its not there in table2; but then also in our report we want that user.

I tried using UNION keyword but the limitation with UNION is that if we are retrieving 3 columns from table1 than from table2 we have to retrieve 3 columns only.
Can we use other function or keyword so that if the column numbers are mismatch then also we will able to get the data.

One more question, I tried with SPUFI but it is showing row limit exceeded. Apart from SPUFI/QMF how can i retrieve the data.

Appreciate your help.
Back to top
View user's profile Send private message
Ketan Varhade

Active User


Joined: 29 Jun 2009
Posts: 197
Location: Mumbai

PostPosted: Tue Sep 08, 2009 12:28 pm
Reply with quote

HI Ruchi,
Please could you explain that on what basis that you want to the data for all the 7 table, is there any connection between the 7 tables, some key ?
Can you give us a example that how should be a desired output look like.

Have you tried using joins?
Back to top
View user's profile Send private message
ruchi.jain

New User


Joined: 17 Sep 2007
Posts: 17
Location: Pune

PostPosted: Tue Sep 08, 2009 1:03 pm
Reply with quote

Hi Ketan,

There is no condition; we want to retrieve the data from all tables. One thing is that 5 tables have 1 column in common: Racfid is the column name.
Other 3 tables are not having this column but they are inter-related between them.

But i want the data like:

Table1 has 3 columns... table2 has 2 columns... table3 has 4 columns.... and so on...
if 1 user is in table1 but not in table2 then also i want the user1 in the report.

The report will contain all the columns name and if user detail is not there in particular column then it will give null value.
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Tue Sep 08, 2009 1:14 pm
Reply with quote

it would be wise to try to understand better the requirement...

from the confusing info provided the quick and dirty answer would be..
run as many queries as the tables You have

also get proper math training...
in the topic title You say 10 tables
in the topic text You say 7
afterward You contradict Yourself again by saying 5 and 3

sloppyness will not make people eager to help You

to get good help You need to post clearly what You have to do,
Back to top
View user's profile Send private message
ruchi.jain

New User


Joined: 17 Sep 2007
Posts: 17
Location: Pune

PostPosted: Tue Sep 08, 2009 1:56 pm
Reply with quote

Hi,

Actually i want data of 10 tables only but i was just giving an example. Ketan asked are there any key column in all the tables so i am giving an example that if there are 8 tables then 5 are having 1 common column and other 3 are inter-related to them.

I am sorry if that misguide you but i really want to fetch data from 10 tables and out of them 7 are having 1 column common and other 3 are inter-related but with other column.

I want to give the data in 1 report only so running as much query as tables is not the feasible method.

I hope now you got the correct statistics.
Please help.
Back to top
View user's profile Send private message
GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1281
Location: Belgium

PostPosted: Tue Sep 08, 2009 2:36 pm
Reply with quote

there are a few ways of full outer joining > 3 tables :

Basic : Nested outer join :
Code:

Select * from
(  Select first2.* ,c.*, coalesce(first2.K1, c.col1) as K1
     from
      (Select a.*,b.*, coalesce(a.col1,b.col1) as K1
         from table1 a
         full outer join table2 b on a.col1 = b.col1) as first2
     full outer join table3 c on c.col1 = first2.K1) as first3
full outer join table4 d on d.col1 = first3.K1


Easier : all in one
Code:
select *
 from           table1 a
full outer join table2 b on b.col1 = a.col1
full outer join table3 c on c.col1 = coalesce (a.col1,b.col1)
full outer join table4 d on d.col1 = coalesce (a.col1,b.col1,c.col1)
full outer join table5 e on e.col1 = coalesce (a.col1,b.col1,c.col1,d.col1)


If outer joining with different columns = combination of the above
suppose :
first 5 table outer join on col1
sixth table outer join on col2 which is also on table1,table3 and table5

Code:
select * from (

select a.*,b.*,c.*,d.*,e.*, coalesce (a.col2,c.col2,e.col2) as K2
 from           table1 a
full outer join table2 b on b.col1 = a.col1
full outer join table3 c on c.col1 = coalesce (a.col1,b.col1)
full outer join table4 d on d.col1 = coalesce (a.col1,b.col1,c.col1)
full outer join table5 e on e.col1 = coalesce (a.col1,b.col1,c.col1,d.col1)
) First5

full outer join table6 F on f.col2 = First5.K2

with very doubtfull results if a.col2 <> c.col2



PS.: you must understand that outer joining > 3 tables is not very performant, because for each 2 tables he must build an intermediate result
Back to top
View user's profile Send private message
sushanth bobby

Senior Member


Joined: 29 Jul 2008
Posts: 1020
Location: India

PostPosted: Tue Sep 08, 2009 2:46 pm
Reply with quote

Hi Ruchi,

Can you give us you sample data and the expected report output along with the query you have tried. It would be a lot helpfull.

Code:
    Try to use CODE tags while posting your sample data.


Thank You,
Sushanth
Back to top
View user's profile Send private message
sushanth bobby

Senior Member


Joined: 29 Jul 2008
Posts: 1020
Location: India

PostPosted: Tue Sep 08, 2009 2:48 pm
Reply with quote

Ha, i should have refreshed my page before posting.

Sushanth
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Wed Sep 09, 2009 12:32 am
Reply with quote

Hello,

If there is a large volume of data to be processed, you might consider unloading all of the data in some common format and doing what you need using the extracted data.

Running high volumes of data thru some poorly performing "query(ies)" will only waste system resources. . .
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 Store the data for fixed length COBOL Programming 1
No new posts Data set Rec-Cnt and Byte-Cnt Testing & Performance 2
No new posts SCOPE PENDING option -check data DB2 2
No new posts Check data with Exception Table DB2 0
No new posts JCL EXEC PARM data in C Java & MQSeries 2
Search our Forums:

Back to Top