Ravindra Kumar
Ravindra Kumar

Reputation: 1

Merging or joining two table with records

Problem like is, we have two tables t1 and t2. t1 have 3 columns and t2 have 2 columns respectively. suppose t1 have 5 records and t2 have 3 records. I want to merge or join both the tables such that records of t2 comes in table t1 after last record. we can make columns like that T1(c1, c2, c3) and T2(c2,c3) where c2 and c3 are same data types in both the tables and c1 makes as primary or unique key.

Upvotes: 0

Views: 118

Answers (4)

some_coder
some_coder

Reputation: 340

You could use an UNIQUE ALL statement (an normal union without "all" returns only distinct values).

select c1, c2, c3 from t1
union all 
select null as c1, c2, c3 from t2

Upvotes: 1

APC
APC

Reputation: 146349

This will return all the rows from the two tables with the rows from T1 appearing before those of T2.

select c1, c2, c3 from t1 
union all  
select null as c1, c2, c3 from t2 
order by nvl2(c1, 0, 1) asc 

The NVL2() command will return 0 when the value for C1 is not null; this is true for all the rows in T1 (it's the primary key) and false for all the rows in T2. The order with the tables is arbitrary, but can be fixed by adding additional columns to the ORDER BY clause.

Upvotes: 1

user1102001
user1102001

Reputation: 707

you can use

UNION

For merging records of more then one table

Upvotes: 0

bpgergo
bpgergo

Reputation: 16047

If understand your post correctly, you want to append the records that can be found in table t2 to table t1.

insert into t1 (c1, c2, c3) (select sequence_for_t1.nextval, c2, c3 from t2)

Upvotes: 0

Related Questions