All Forums Database
esharma 15 posts Joined 08/15
12 Aug 2015
stacking two tables

I have two tables in same database like one is back book and one is new. Now i want to see data in one go- means i want to stack my both tables. Could you please help me in answering following questions
1. The name of columns are similar but the definition of few are not. So is it possible to stack these tables?
2. can i add new column to volatile table? for eg. alter table abc(volatile table) add column VARCHAR(100) null
 
 
 

Ena
dnoeth 4628 posts Joined 11/04
12 Aug 2015

What do you mean by stack, probably a UNION ALL?
The first SELECT of a UNION determines the column names and datatypes, you can CAST a column to match the datatype of the 2nd table.
 
ALTER TABLE is not supported for Volatile Tables, you have to think before you create it :-)

Dieter

esharma 15 posts Joined 08/15
12 Aug 2015

thanks dnoeth!
one thing more. i have two tables- but table 1 has two extra column. is it still possible to union the.
for eg; table 1- pol_cnl_typ,campaign_descrip,cnl_code
and table 2 -pol_cnl_typ
How can i union them. I do not want to alter my original table here as that will confuse other users.

Ena

dnoeth 4628 posts Joined 11/04
12 Aug 2015

Simply add a CAST(NULL AS ...) using a matching datatype in the 2nd SELECT.

Dieter

You must sign in to leave a comment.