A table underneath another one - Mailing list pgsql-general

From Jose Antonio Leo
Subject A table underneath another one
Date
Msg-id AEEGKNMMPPBJJDLEJDODIEPDCJAA.jaleo8@storelandia.com
Whole thread Raw
List pgsql-general
Hi to all,
I have three tables, one reflects article sales, another article purchases and another article regulations.
I would like to make a pursuit of a concrete article from an initial date to another end and to see his history.
The three tables agree in the following fields
    code_article, date, units, .......
 
In order to make a pursuit it would have to unite the three tables ordering per dates and later to select the rank of dates selec.
 
How I can do this? How I can to place a table underneath another one?
I have thought to create a view or one temporary table with the union. And later to make the consultation on that table.
What seems to you?
 
create view V_move as
(select cod_pto,date,code_article,units,tip_mov
FROM sales WHERE (date>='2002/08/1' and date<='2002/10/10' and cod_pto='31180')
UNION
select cod_pto,date,code_article,units,tip_mov
FROM purchase WHERE (date>='2002/08/1' and date<='2002/10/10' and cod_pto='31180')
UNION
select cod_pto,date,code_article,units,tip_mov
FROM regula WHERE WHERE (date>='2002/08/1' and date<='2002/10/10' and cod_pto='31180')
order by date);
 

Select cod_pto,date,code_article,units,TIP_MOV.des_reg
From V_mov
    INNER JOIN TIPO_MOV on TIPO_MOV.cod_reg= V_move.tip_mov;
 
DROP VIEW V_movimientos;
 
 
Tk very much.

pgsql-general by date:

Previous
From: "Patrick Fiche"
Date:
Subject: Re: pg_attribute always grow...
Next
From: Shane Wright
Date:
Subject: Re: PostgreSQL query failed: COPY state must be terminated first