View previous topic :: View next topic |
Author |
Message |
Sarangadhar Beginner
Joined: 14 Oct 2004 Posts: 130 Topics: 43 Location: virtual village
|
Posted: Thu Oct 11, 2007 7:43 pm Post subject: selection of table info in FULL OUTER JOIN |
|
|
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 |
|
 |
Sarangadhar Beginner
Joined: 14 Oct 2004 Posts: 130 Topics: 43 Location: virtual village
|
Posted: Fri Oct 12, 2007 12:10 am Post subject: |
|
|
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 |
|
 |
vivek1983 Intermediate

Joined: 20 Apr 2006 Posts: 222 Topics: 24
|
|
Back to top |
|
 |
vkphani Intermediate

Joined: 05 Sep 2003 Posts: 483 Topics: 48
|
Posted: Fri Oct 19, 2007 6:17 am Post subject: |
|
|
You can use VALUE function too as mentioned below:
SELECT VALUE(COL1,COL2) as member |
|
Back to top |
|
 |
Sarangadhar Beginner
Joined: 14 Oct 2004 Posts: 130 Topics: 43 Location: virtual village
|
Posted: Tue Oct 30, 2007 5:56 pm Post subject: |
|
|
Thanks all..
I am using COALESCE function _________________ Thanks |
|
Back to top |
|
 |
|
|