Re: join two tables with sharing some columns between two - Mailing list pgsql-sql

From Phillip Smith
Subject Re: join two tables with sharing some columns between two
Date
Msg-id 004b01c69e46$a308a570$9b0014ac@ITPhil
Whole thread Raw
In response to join two tables with sharing some columns between two  ("filippo" <filippo2991@virgilio.it>)
List pgsql-sql
If I understand correctly... I think this should work:

SELECT    table1.id,    table1.person_name,    table2.car_description,    table1.date_arrival,    table1.date_departure
FROM    table1, table2
WHERE    table1.id = table2.id
;

Assuming the date_arrival and date_departure fields are the same on both
tables then it doesn't matter if you pull them from table1 or table2,
otherwise you'll need to change the SELECT appropriately.

If you want it to go in to a new table as well as opposed to just a query,
you could have a play with SELECT INTO...

Cheers,
-p

-----Original Message-----
From: pgsql-sql-owner@postgresql.org [mailto:pgsql-sql-owner@postgresql.org]
On Behalf Of filippo
Sent: Monday, 26 June 2006 23:39
To: pgsql-sql@postgresql.org
Subject: [SQL] join two tables with sharing some columns between two

Hi,

I have two tables like these: (this is an example, the actual tables
have diffferent fields and meanings)

TABLE1
id
person_name
date_arrival
date_departure

TABLE2
id
car_description
date_arrival
date_departure

I'd like to make a query to have such resulting table

RESULTING_TABLE
id
person_name
car_description
date_arrival
date_departure

the id is the primary key for the three tables and it's unique for the
three (id in table1 cannot be in table2, I use the same counter to
generate the id for table1 and table2).


I is possible to create such a query?

Thanks


---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate      subscribe-nomail command to
majordomo@postgresql.orgso that your      message can get through to the mailing list cleanly 


*******************Confidentiality and Privilege Notice*******************

The material contained in this message is privileged and confidential to
the addressee.  If you are not the addressee indicated in this message or
responsible for delivery of the message to such person, you may not copy
or deliver this message to anyone, and you should destroy it and kindly
notify the sender by reply email.

Information in this message that does not relate to the official business
of Weatherbeeta must be treated as neither given nor endorsed by Weatherbeeta.
Weatherbeeta, its employees, contractors or associates shall not be liable
for direct, indirect or consequential loss arising from transmission of this
message or any attachments


pgsql-sql by date:

Previous
From: Hima Surapaneni
Date:
Subject: Can't drop table
Next
From: Richard Broersma Jr
Date:
Subject: Re: Can't drop table