Re: select from multiple tables

From: Lew <noone(at)lewscanon(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: Re: select from multiple tables
Date: 2012-06-18 13:43:46
Message-ID: jrnba8$v2t$1@news.albasani.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Steve Crawford wrote:
> e-letter wrote:
>> Readers,
>>
>> A database has table1, table2, table3, table4 and each table has
>> columns of text and integers:
>>
>> table1
>> text1, 10
>> text2, 20
>> text3, 30
>> text4, 40
>> text5, 50
>> text6, 60
>> text7, 70
>> text8, 80
>>
>> table2
>> text1, 10
>> text2, 20
>>
>> table3
>> text3, 30
>> text4, 40
>>
>> table4
>> text5, 50
>>
>> Is it possible to create a new table (table5) by creating a query that
>> selects rows that _both_ exist in table1 _and_ are not in any of the
>> preceding tables (table2, table3, table4)?
>>
>> Thanks in advance.
>
> create table table5 as
> select textcol, intcol from table1 except
> (
> select textcol, intcol from table2 union
> select textcol, intcol from table3 union
> select textcol, intcol from table3
> );

But why into a separate table?

Isn't just having a SELECT result sufficient? Storing it is a denorm.

Wouldn't a VIEW be better?

--
Lew
Honi soit qui mal y pense.
http://upload.wikimedia.org/wikipedia/commons/c/cf/Friz.jpg

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Alessandro Gagliardi 2012-06-18 16:43:01 Re: select from multiple tables
Previous Message Joseph Marlin 2012-06-18 13:29:24 Impatient warm standby - Recovery spam in pg_log/startup.log