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 

selection of table info in FULL OUTER JOIN

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


Joined: 14 Oct 2004
Posts: 130
Topics: 43
Location: virtual village

PostPosted: Thu Oct 11, 2007 7:43 pm    Post subject: selection of table info in FULL OUTER JOIN Reply with quote

I have a situation as below:
table1 - col1, col2, col3, col4-col10
table2 - col1, col2, col3, col4-col10
Table1 will have recent data, and table 2 will have historical data.
I need to get all unique combinations of col1 and col2 from both the tables together, and corresponding col4-col10 values. TABLE1 will have some col1 col2 combinations which are not present in table2 and vice versa.

If a combination present in both the tables, then I need the information (col4-col10) from tab1, as this is recent info. Otherwise, I need the information present that table where that combination exist.

One fact about data is -> col4-col10 values are same for the same combination of col1 and col2 even though there are more than one rows present for each col1 and col2 combination.

There will be millions of rows in the table, but the unique number of col1 and col2 combinations will be less than 2000.

I can try a CASE statement in select clause to see whether the combination is present in table1 from FULL OUTER JOIN between tables. Pick the information from table one if table1 row is present, other wise pick from table 2. But since there are nearly 10 columns, I need 10 case statements which look ugly. Is there any better way?

Please let me know if you need any more info.

Eg.:
Code:
Tab1
Col1   Col2   Col3   Col4-col10
1              1   1   123
1   1   2   123
1   2   1   1234
1   2   2   1234
1   4   1   141
1   4   2   141

Code:
Tab2
Col1   Col2   Col3   Col4-col10
1   1   1   123
1   1   2   123
1   2   1   555
1   2   2   555
1   3   1   456
1   3   2   456



Code:
output table is:
Col1   Col2   Col3   Col4-col10
1   1   1   123
1   2   1   1234
1   3   1   456
1   4   2   141

_________________
Thanks
Back to top
View user's profile Send private message
Sarangadhar
Beginner


Joined: 14 Oct 2004
Posts: 130
Topics: 43
Location: virtual village

PostPosted: Fri Oct 12, 2007 12:10 am    Post subject: Reply with quote

above one got solved.

but I wanted to know which one is efficient of below when used in a SELECT caluse:
Code:
1. IFNULL(COL1, COL2)AS MEMBER

2. CASE WHEN COL1 IS NOT NULL
        THEN COL1
        ELSE COL2
        END AS MEMBER

_________________
Thanks
Back to top
View user's profile Send private message
vivek1983
Intermediate


Joined: 20 Apr 2006
Posts: 222
Topics: 24

PostPosted: Fri Oct 12, 2007 1:12 am    Post subject: Reply with quote

Sarangadhar,

I am using COALESCE function which is an optimized one for such a scenario.

SELECT COALESCE(COL1,COL2) as member

For information check the below link:

http://publib.boulder.ibm.com/infocenter/dzichelp/v2r2/index.jsp?topic=/com.ibm.db29.doc.sqlref/fifnull.htm
_________________
Vivek G
--------------------------------------
A dream is just a dream. A goal is a dream with a plan and a deadline. (Harvey Mackay)
Back to top
View user's profile Send private message
vkphani
Intermediate


Joined: 05 Sep 2003
Posts: 483
Topics: 48

PostPosted: Fri Oct 19, 2007 6:17 am    Post subject: Reply with quote

You can use VALUE function too as mentioned below:
SELECT VALUE(COL1,COL2) as member
Back to top
View user's profile Send private message Send e-mail
Sarangadhar
Beginner


Joined: 14 Oct 2004
Posts: 130
Topics: 43
Location: virtual village

PostPosted: Tue Oct 30, 2007 5:56 pm    Post subject: Reply with quote

Thanks all..

I am using COALESCE function
_________________
Thanks
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