From: Dipl.-Ing. Thomas Schallar <T.Schallar@AVALON.at>
To: pgsql-sql@postgresql.org
Subject: SELECT multiple tables with same fields
Date: Sun, 29 Aug 1999 02:24:18 +0200
Message-ID: <37C87DB2.A7A516F2@AVALON.at> (raw)
Hello!
Imagine two tables
CREATE TABLE one ( name varchar(10), content varchar(10) );
CREATE TABLE two ( name varchar(10), something_different varchar(10) );
with some rows in each of them and and a query
SELECT *
INTO new_table
FROM one, two
WHERE one.name=two.name;
If there are matching fields, then the query would return some joined
rows. But it can't, because the column "name" comes twice in the tables!
Of course
SELECT one.*, two.name AS two_name, two.something_different
INTO new_table
FROM one, two
WHERE one.name=two.name;
does the work, because I rename the duplicate columns.
Before I started programming with Postgres I've done my stuff with
Microsoft Visual Basic and Access. Access has the lovely feature, that
doubly selected column names are automatically renamed to
<tablename>.<columname> (or <tablename>_<columname>? I can't remember at
the moment; sorry!) so everything works fine.
Is there some similar feature in Postgres? I'm asking, because I have
queries over up to seven tables joined and the fields in those tables
are growing larger and larger. But if I add fields, than I have to add
them to each of the SELECT statements also, that they won't be missed
off. That's boaring und faulty.
Any help welcome!
regards,
Thomas
(Vienna, Austria, Europe)
By the way: I'm not subscribed to this mailing list. Please write any
help directly to my e-mail address. Thank you!
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-sql@postgresql.org
Cc: T.Schallar@AVALON.at
Subject: Re: SELECT multiple tables with same fields
In-Reply-To: <37C87DB2.A7A516F2@AVALON.at>
References: <37C87DB2.A7A516F2@AVALON.at>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox