SELECT multiple tables with same fields - Mailing list pgsql-sql

From Dipl.-Ing. Thomas Schallar
Subject SELECT multiple tables with same fields
Date
Msg-id 37C87DB2.A7A516F2@AVALON.at
Whole thread Raw
List 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)


By the way: I'm not subscribed to this mailing list. Please write any
help directly to my e-mail address. Thank you!




pgsql-sql by date:

Previous
From: "tjk@tksoft.com"
Date:
Subject: Re: [SQL] datetime query issue
Next
From: "Dipl.-Ing. Thomas Schallar"
Date:
Subject: LEFT or RIGHT JOINs?