SELECT multiple tables with same fields
От | Dipl.-Ing. Thomas Schallar |
---|---|
Тема | SELECT multiple tables with same fields |
Дата | |
Msg-id | 37C95508.B50F49BD@AVALON.at обсуждение исходный текст |
Ответы |
Re: [SQL] SELECT multiple tables with same fields
Re: [SQL] SELECT multiple tables with same fields |
Список | 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)
В списке pgsql-sql по дате отправления: