Re: 2 tables, joins and same name...

From: Thomas Rehlich <rehlich(at)wtal(dot)de>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: 2 tables, joins and same name...
Date: 2001-08-31 15:55:15
Message-ID: 3B8FB363.1000509@wtal.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Marc André Paquin wrote:

> Here is 2 tables:
>
> airport
> ---------
> airport_id
> name
> code
> city_id
>
> destination
> -----------
> destination_id
> dest_name
> ...
> airport_dep_id // using airport.airport_id (departure)
> airport_arr_id // using airport.airport_id has well (arrival)
>
> I have 2 columns in the second table that uses the same name column in
> the first table...
>
> I dont know how to formulate my SQL query... I want to select the
> destinations in the destination table with not the ID of each airport
> but their names. I can do a join with one but with the second one, I
> get no results... And this is confusing!

May be I'm wrong, but I think you mean something like this one

select dest_name
, air1.name as airport1
, air2.name as airport2
from destination
join airport as air1
on air1.airport_id = destination.airport_dep_id
join airport as air2
on air2.airport_id = destination.airport_arr_id

Thomas

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Mikheev, Vadim 2001-08-31 16:45:49 Re: getting the oid for a new tuple in a BEFORE trigger
Previous Message Josh Berkus 2001-08-31 15:29:21 Re: 2 tables, joins and same name...