select column from two queries

Database
The Teradata Database channel includes discussions around advanced Teradata features such as high-performance parallel database technology, the optimizer, mixed workload management solutions, and other related technologies.
Fan

select column from two queries


how to write a select statment to choose columns from both queries

d.column1 , e.column2, e.column3 , c.column4 , b.column5 , f.column6 , b.column8 , b.column9 ,
b. column10 , amount column from outerjoin table

 

(select d.column1 , e.column2, e.column3 , c.column4 , b.column5 , f.column6 , b.column8 , b.column9 , b. column10
from Schema.table1 b , table2 c, table3 d, table4 e, table5 f
where c.column1=b.column1
and d.column2=b.column2
and f.column3=b.column3
and e.column4=c.column4 ) SQL1
Left outer join (select Amount from schema.amountable1 where Yr_Nb=extract(year from current_date) and Scnr_Id= (select max(Scnr_Id) from schema. amountable1) SQL2
on SQL2.column1 = SQL1.column1
 

 

vs

1 REPLY
Senior Apprentice

Re: select column from two queries

Hi,

 

Although I can't see it I assume that this has been answered. What you've got are two derived tables (SQL1 and SQL2, your outer query simply selects the required columns from thos two tables (you've already done all the hard-work!).

 

Try

 

select sql1.column1 , sql1.column2, sql1.column3 , sql1.column4 , sql1.column5 , sql1.column6 , sql1.column8 , sql1.column9 ,
sql1.column10 , sql2.amount (select d.column1 , e.column2, e.column3 , c.column4 , b.column5 , f.column6 , b.column8 , b.column9 , b. column10 from Schema.table1 b , table2 c, table3 d, table4 e, table5 f where c.column1=b.column1 and d.column2=b.column2 and f.column3=b.column3 and e.column4=c.column4 ) SQL1 Left outer join (select Amount from schema.amountable1 where Yr_Nb=extract(year from current_date) and Scnr_Id= (select max(Scnr_Id) from schema. amountable1) SQL2 on SQL2.column1 = SQL1.column1

 

Cheers,

Dave

 

 

Ward Analytics Ltd - information in motion
www: http://www.ward-analytics.com