A table underneath another one

From: "Jose Antonio Leo" <jaleo8(at)storelandia(dot)com>
To: <pgsql-general(at)postgresql(dot)org>
Subject: A table underneath another one
Date: 2002-10-18 10:45:04
Message-ID: AEEGKNMMPPBJJDLEJDODIEPDCJAA.jaleo8@storelandia.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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_move
INNER JOIN TIPO_MOV on TIPO_MOV.cod_reg= V_move.tip_mov;

DROP VIEW V_movimientos;

Tk very much.

Browse pgsql-general by date

  From Date Subject
Next Message Paul 2002-10-18 11:44:31 select into without creating new table
Previous Message Shane Wright 2002-10-18 10:44:48 Re: PostgreSQL query failed: COPY state must be terminated first