views:

126

answers:

3

I want to create a table that stores values from two different tables;

From table 1: cust_id (varchar2), invoice_amt (float)

From table 2: cust_id (from table 1), payment_date

My table should have 3 fields:

cust_id, invoice_amt, payment_date

I tried the following, which is obviously wrong.

create table temp1 as (
    select table_1.cust_id, table_1.invoice_amt, table_2.payment_date
      from table_1@dblink, table_2@dblink)

Your valuable suggestions will be of great help.

+3  A: 
create table temp1 as (
    select 
        table_1.cust_id,
        table_1.invoice_amt,
        table_2.payment_date 
    from 
        table_1@dblink, 
        table_2@dblink 
    where 
        table_1.cust_id = table_2.cust_id
    )

I'm no oracle guy, but that should do what you want (untested, though).

inkedmn
+1  A: 

You were close:

create table temp1 as ( 
    select t1.cust_id, t1.invoice_amt, t2.payment_date 
      from table_1@dblink t1, table_2@dblink t2 
     where t1.cust_id=t2.cust_id)
Dennis Baker
+1  A: 

It depends on what you're going to use it for, but I'd be sorely tempted to use a view instead of a table:

create view temp1(cust_id, invoice_amt, payment_date) as
    select t1.cust_id, t1.invoice_amt, t2.payment_date 
      from table_1@dblink as t1 inner join table_2@dblink as t2
           on t1.cust_id = t2.cust_id

The advantage is it always contains the values from the current versions of table_1 and table_2. The disadvantage is that you cannot edit the view (or, if you can, your edits affect the underlying tables as well as the view).

Jonathan Leffler
The disadvantage is also that you have to pull data over DB link for every query to that view.
jva