Quantcast
Channel: Teradata Forums - Database
Viewing all articles
Browse latest Browse all 14773

fetching data by joining 2 tables in a view - response (9) by Arun1377

$
0
0

Hi Ulrich,
PFB the DDLs , data in the table and the select statement in the view.
CREATE MULTISET TABLE DB_TEST.T1 ,NO FALLBACK ,
NO BEFORE JOURNAL,
NO AFTER JOURNAL,
CHECKSUM = DEFAULT,
(
A DECIMAL(15,0),
B DECIMAL(15,0),
JOINkey1 INTEGER,
JOINkey2 INTEGER,
JOINkey3 INTEGER,
JOINkey4 INTEGER,
NO1 INTEGER,
NO2 INTEGER,
NO3 INTEGER,
NO4 INTEGER,
insert_dt DATE FORMAT 'YY/MM/DD')
PRIMARY INDEX ( A );

CREATE MULTISET TABLE DB_TEST.T2 ,NO FALLBACK ,
NO BEFORE JOURNAL,
NO AFTER JOURNAL,
CHECKSUM = DEFAULT,
(
Dept_id INTEGER,
A INTEGER,
B INTEGER,
newfield CHAR(5) CHARACTER SET LATIN NOT CASESPECIFIC)
PRIMARY INDEX ( Dept_id );
Data in Table T1 is :
A B JOINkey1 JOINkey2 JOINkey3 JOINkey4 NO1 NO2 NO3 NO4 insert_dt
1234 1111 12 13 14 15 16 17 18 19 11/19/2013
1235 1112 13 14 15 16 17 18 19 20 11/19/2013
1236 1113 14 15 16 17 18 19 20 21 11/19/2013
1237 1114 15 16 17 18 19 20 21 22 11/19/2013
1238 1115 16 17 18 19 20 21 22 23 11/19/2013
1239 1116 17 18 19 20 21 22 23 24 11/19/2013
1240 1117 18 19 20 21 22 23 24 25 11/19/2013

Data in table T2
 Dept_id A B newfield
111 12 16 ABCD 
222 13 17 EFGH 
333 14 18 IJKL 
444 15 19 MNOP 

I need the data to be displayed as:
A B newfield newfield newfield newfield
1234 1111 ABCD  EFGH  IJKL  MNOP 
1235 1112 EFGH  IJKL  MNOP  ?
1236 1113 IJKL  MNOP  ? ?
1237 1114 MNOP  ? ? ?
1238 1115 ? ? ? ?
1239 1116 ? ? ? ?
1240 1117 ? ? ? ?

Currently i am using the below SELECT statement in the view:
sel
T1. A ,
T1.B ,
T2.newfield,
T21.newfield,
T22.newfield,
T23.newfield
from DB_TEST.T1 T1
left outer join DB_TEST.T2 T2
on T1.JOINkey1 = T2.A and
T1.NO1 = T2.B
left outer join DB_TEST.T2 T21
on T1.JOINkey2 = T21.A and
T1.NO2 = T21.B
left outer join DB_TEST.T2 T22
on T1.JOINkey3 = T22.A and
T1.NO3 = T22.B
left outer join DB_TEST.T2 T23
on T1.JOINkey4 = T23.A and
T1.NO4 = T23.B
Kindly help me to improve the performance by avoiding the 4 joins over the same table.
--Arun


Viewing all articles
Browse latest Browse all 14773

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>