pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Thomas Rehlich <rehlich@wtal.de>
To: pgsql-sql@postgresql.org
Subject: Re: 2 tables, joins and same name...
Date: Fri, 31 Aug 2001 17:55:15 +0200
Message-ID: <3B8FB363.1000509@wtal.de> (raw)
References: <3B8EA145.1E9349F3@inter-resa.com>

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




view thread (11+ messages)  latest in thread

Message-ID: <3B8FB363.1000509@wtal.de>
Permalink:  ../3B8FB363.1000509@wtal.de/
Also on:    postgresql.org/message-id/3B8FB363.1000509@wtal.de

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: rehlich@wtal.de
  Subject: Re: 2 tables, joins and same name...
  In-Reply-To: <3B8FB363.1000509@wtal.de>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox