Re: inserting columns with values from a different table

From: Frank Miles <fpm(at)u(dot)washington(dot)edu>
To: Alexander Turchin <aturchin(at)chip(dot)org>
Cc: PostgreSQL Mailing List <pgsql-general(at)postgresql(dot)org>
Subject: Re: inserting columns with values from a different table
Date: 2001-07-09 04:32:45
Message-ID: Pine.A41.4.33.0107082130180.44188-100000@mead2.u.washington.edu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Sun, 8 Jul 2001, Alexander Turchin wrote:

> This may be (hopefully) a very basic question, but I (admittedly, a
> pgsql newbie) cannot seem to be able to find an answer to it :(
>
> I have in my database tables, say A, B, and C, all of them referring to
> the same objects (e.g. table A contains customer's name, table B his/her
> purchases, and table C his/her address). I want to create a "master"
> table D whose rows would have some values from table A, some from B, and
> some from C (e.g. name, last purchase, and address). I know I can do an
> INSERT with SELECT - but that will only allow me to insert values from
> one table, not from all three (or more). Is there any way to do this in
> PostgreSQL?
>
> I do realize that I could likely imitate everything I need from a master
> table by having many different tables and executing [more or less]
> complicated queries, but having a "master" table would greatly simplify
> my life and avoid multiple potential mistakes when constructing those
> queries...

You may want to check out CREATE VIEW: from within psql:

\h create view
Command: CREATE VIEW
Description: Constructs a virtual table
Syntax:
CREATE VIEW view AS SELECT query

More information is available in the documentation.

-frank

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Stephan Szabo 2001-07-09 06:41:19 Re: inserting columns with values from a different table
Previous Message Gregory Wood 2001-07-09 04:31:43 Re: inserting columns with values from a different table