From: | "Dipl(dot)-Ing(dot) Thomas Schallar" <T(dot)Schallar(at)AVALON(dot)at> |
---|---|
To: | pgsql-sql(at)postgresql(dot)org |
Subject: | SELECT multiple tables with same fields |
Date: | 1999-08-29 15:43:04 |
Message-ID: | 37C95508.B50F49BD@AVALON.at |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
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)
From | Date | Subject | |
---|---|---|---|
Next Message | Dipl.-Ing. Thomas Schallar | 1999-08-29 15:43:43 | LEFT or RIGHT JOINs? |
Previous Message | Tom Lane | 1999-08-29 01:00:46 | Re: [HACKERS] entries in pg_shadow |