Re: join two tables with sharing some columns between two

From: "Phillip Smith" <phillips(at)weatherbeeta(dot)com(dot)au>
To: <pgsql-sql(at)postgresql(dot)org>
Subject: Re: join two tables with sharing some columns between two
Date: 2006-07-03 02:16:04
Message-ID: 004b01c69e46$a308a570$9b0014ac@ITPhil
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)postgresql(dot)org [mailto:pgsql-sql-owner(at)postgresql(dot)org]
On Behalf Of filippo
Sent: Monday, 26 June 2006 23:39
To: pgsql-sql(at)postgresql(dot)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(at)postgresql(dot)org so 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

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Richard Broersma Jr 2006-07-03 02:30:00 Re: Can't drop table
Previous Message Richard Broersma Jr 2006-07-03 01:52:26 Re: Alternative to Select in table check constraint